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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide marked walkTokens option to help with relative markdown links #64

Open
webketje opened this issue Nov 21, 2022 · 0 comments
Open

Comments

@webketje
Copy link
Member

webketje commented Nov 21, 2022

Please thumbs up 馃憤 this comment if you would like to use this feature, or thumbs down 馃憥 if you don't think it should be added . Your feedback is valued


Various editors provide typehint support for linking to local files.
A function like below could help auto-transform source links to html permalinks.

walkTokens(token) {
    if (token.type === 'link') {
      if (token.href.endsWith('index.md')) {
        token.href = token.href.replace(/\index.md$/, '')
      }
      if (token.href.startsWith('.')) {
        token.href = baseUrl + '/' + relative(metalsmith.source(), metalsmith.path('src',token.href)).replace(/\\/g, '/')
        console.log(token)
      }
    }
  }

To consider:

  • need to resolve relative to linking page's __filename
  • complications when the root of the repo !== metalsmith.directory
  • complications when a path-transforming plugin like metalsmith/permalinks is used after the markdown conversion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant