Skip to content

Commit a5345fb

Browse files
Merge pull request #52 from commitd/sh/51
Add remark preprocessor to remove trailing .md from links
2 parents 096e9d0 + 8f07150 commit a5345fb

File tree

7 files changed

+36
-7
lines changed

7 files changed

+36
-7
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ A theme for writing documentation sites in Markdown.
2626
- SEO friendly
2727
- Fully customizable
2828
- 🔍 Search
29+
- Use links that work in github
2930

3031
## 🔗 Live Demo and Instructions
3132

@@ -114,7 +115,7 @@ Canonical URLs are generated automatically.
114115

115116
## Development
116117

117-
We use yarn workspaces to develop the theme alongside an example usage that also serves as a documentation site for this project.
118+
We use workspaces to develop the theme alongside an example usage that also serves as a documentation site for this project.
118119

119120
On first use run
120121

@@ -161,5 +162,5 @@ site of someone who installed and used your theme.
161162
You can run the example with:
162163

163164
```shell
164-
yarn workspace example develop
165+
npm run start
165166
```

example/docs/instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Further options are available to customize, detailed below.
4343

4444
The `index.md(x)` file is shown on load.
4545

46-
Each documentation page can add frontmatter that is used to improve SEO. You can add metadata, [order](ordered/index) the pages and add user friendly links:
46+
Each documentation page can add frontmatter that is used to improve SEO. You can add metadata, [order](ordered/index.md) the pages and add user friendly links:
4747

4848
```markup
4949
---
@@ -56,7 +56,7 @@ metaTescription: "This is the meta tag description, , but will default to descri
5656
---
5757
```
5858

59-
If no title is provided the filename is used. The sidebar is populated from the files in `docs` folder and supports [nesting](nested/index) in sub-folders. At each level the contents are sorted using alphanumerically using the order frontmatter or the title.
59+
If no title is provided the filename is used. The sidebar is populated from the files in `docs` folder and supports [nesting](nested/index.md) in sub-folders. At each level the contents are sorted using alphanumerically using the order frontmatter or the title.
6060

6161
## Navigation
6262

example/docs/ordered/oa.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ title: Order A
33
order: '2'
44
---
55

6-
In this example although the title `Order A` is before [`Order B`](ob) the `order` front matter is used to sort the files.
6+
In this example although the title `Order A` is before [`Order B`](ob.md) the `order` front matter is used to sort the files.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

theme/gatsby-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ module.exports = ({
7070
],
7171
],
7272
gatsbyRemarkPlugins: [
73+
{
74+
resolve: require.resolve(`./plugins/fix-links`),
75+
},
7376
{
7477
resolve: require.resolve(`./plugins/fix-mermaid-pre`),
7578
},

theme/plugins/fix-links/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const visit = require('unist-util-visit')
2+
module.exports = ({ markdownAST }, pluginOptions) => {
3+
const protocols = ['mailto:', 'http://', 'ftp:', 'https://']
4+
5+
visit(markdownAST, 'link', (node) => {
6+
// Any link we find which isn't internal, then ignore it
7+
if (protocols.find((p) => node.url.startsWith(p))) {
8+
return
9+
}
10+
const old = node.url
11+
node.url = node.url.replace(/\.md$/, '')
12+
})
13+
return markdownAST
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "fix-links",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Committed Software <[email protected]> (http://committed.io)",
10+
"license": "MIT"
11+
}

0 commit comments

Comments
 (0)