Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't prefix link fragments (#) and clear caches before each build. #32

Merged
merged 2 commits into from Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"develop": "gatsby develop",
"start": "gatsby develop",
"build": "rm -rf .cache/gatsby-source-git/ && gatsby build",
"build": "gatsby clean && gatsby build",
"serve": "gatsby serve",
"clean": "gatsby clean",
"lint": "eslint --color --ext .js --ignore-path .gitignore ."
Expand Down
6 changes: 5 additions & 1 deletion plugins/gatsby-remark-prefix-relative-links/index.js
Expand Up @@ -8,7 +8,11 @@ module.exports = ({ markdownAST, markdownNode }, options = {}) => {

const appendPrefix = () => {
visit(markdownAST, 'link', (node) => {
if (node && !node.url.startsWith('http')) {
if (!node || !node.url) return;
const isAbsolute = node.url.startsWith('http');
const isFragment = node.url.startsWith('#');
const requiresPrefix = !isAbsolute && !isFragment;
if (requiresPrefix) {
node.url = `${prefix}/${node.url}`
.replace('index.md', '')
.replace('.md', '/')
Expand Down