binyamin / eleventy-garden

:seedling: A starter site for building a mind garden with eleventy
https://eleventy-garden.netlify.app
MIT License
451 stars 48 forks source link

Conflict between wikilinks and permalinks #77

Open jebeaudoin opened 2 years ago

jebeaudoin commented 2 years ago

Describe the bug I hate even to call this a "bug" -- but if I use Eleventy's permalink functionality to rewrite a URL, the wikilinks functionality won't be able to convert the link correctly.

To Reproduce

  1. Successfully install eleventy-garden
  2. Note that the regex substitution binyamin uses replaces any white space in a filename with a %20, so that a note named "my great file" produces the URL "/notes/my%20great%20file/"
  3. Use the "permalink" key in the template's front-matter to set the URL for "my great file" to "/notes/my-great-file/"

Help needed I'm not a developer (obviously) but I think the issue is that what I am calling the "wikilinks" function rewrites the link using the standard escape characters for spaces. Can someone show me where in the code I can change the regex that is replacing the spaces with %20 -- so that I can simply change them to dashes?

Thanks in advance! jack

binyamin commented 2 years ago

Thanks for bringing this up. When you write "wikilinks functionality", are you referring to how [[ cool title ]] links to /notes/cool%20title/? I want to be sure I'm understanding this correctly.

jebeaudoin commented 2 years ago

Yes, that is correct. Your example is spot on:

[[ cool title ]] links to /notes/cool%20title/?

When I use eleventy's permalinks, I need:

[[ cool title ]] to link to /notes/cool-title/

I'm only guessing about the cause because, as I've said, I'm not a coder. But I wondered if it is in the regex you created?

BTW, I'm loving the work you did to get this going! Thanks so much.

On Sun, Feb 20, 2022 at 8:59 AM Binyamin Aron Green < @.***> wrote:

Thanks for bringing this up. When you write "wikilinks functionality", are you referring to how [[ cool title ]] links to /notes/cool%20title/? I want to be sure I'm understanding this correctly.

— Reply to this email directly, view it on GitHub https://github.com/binyamin/eleventy-garden/issues/77#issuecomment-1046278977, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACT3WG24B72YSZIEGAKV5D3U4EMW3ANCNFSM5OZUKDWA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

asbjornb commented 2 years ago

I'm not strong in this whole setup but I think the wikilinks to url's mostly happens inside of markdownit. You might be able to tweak behavour from inside your .eleventy.js file - line 9-23 sets some options for that component. Probably check out documentation here: https://github.com/markdown-it/linkify-it

Actually - try changing line 18 from parts[0] = parts[0].replace(/.(md|markdown)\s?$/i, ""); to parts[0] = parts[0].replace(/.(md|markdown)\s?$/i, "").replace(" ", "-"); That might do it.

However doing so might also break backlinking in this templates notes. You might need to alter the compare for example in notes.11tydata.js line 6-8 or something.

A workaround might be to use the [[my-note|my note]] syntax to link to the note correctly while displaying another text. I tend to agree with you though that being able to configure a bit more fuzzy matching on linking would be pretty nice, but other tools in this space seem to have the same restrictions, so begrudgingly I've transformed my notes to link with dashes, all lower case etc. Being pretty bad at js and webdev that seemed to be the easier option ;)

freyquency commented 1 year ago

Actually - try changing line 18 from parts[0] = parts[0].replace(/.(md|markdown)\s?$/i, ""); to parts[0] = parts[0].replace(/.(md|markdown)\s?$/i, "").replace(" ", "-");

This seems to replace the first space with a - but not the rest. It also the space in the visible output as well, the equivalent of [[link-to post]]

I'm not familiar with what Eleventy or Markdown-IT does enough to know how to do it, but it seems like running slugify on the link after it's processed by Markdown-IT may be a solution.

The other issue is that somewhere the files are going from link to post.md to link to post without .html at the end. To be in line with Eleventy's default settings it makes sense that each one would converted to link to post/index.html

binyamin commented 1 year ago

@jebeaudoin I extracted the core functionality here, and packaged it into an Eleventy Pplugin. If this is still a problem, please let me know over there.

jebeaudoin commented 1 year ago

I will give this a whirl! Thanks so much.