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

Support for a 'backlinks' widget #315

Closed
sagarbehere opened this issue Dec 26, 2021 · 6 comments
Closed

Support for a 'backlinks' widget #315

sagarbehere opened this issue Dec 26, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@sagarbehere
Copy link
Contributor

This feature request is related to the use case of creating a 'Digital Garden' mentioned in #314 .

It would be great to have a couple of cards that can be placed either in the right sidebar (like the taxonomy cards) or under a post (like the related posts card).

One of these cards would list all the "forward/outgoing links" from the blog post/single page i.e. all the hyperlinks (to internal or external pages) present in the blog post/single page.

The second of these cards would list all the "back links" to the blog post/single page i.e. which other posts/pages contain a link to this page?

Examples/Inspiration

  1. The Hugo Connectome theme has exactly this feature. See the screenshot in the README page which has exactly similar right sidebar widgets with forward/outgoing and backlinks.
  2. This blog post explains how to create a Hugo template that will add backlinks to a note.
  3. See this digital garden whose notes have a 'backlinks' section (Titled 'Links to this page') at the bottom of many of the notes.
@sagarbehere sagarbehere added the enhancement New feature or request label Dec 26, 2021
@razonyang
Copy link
Owner

I'm afraid there will be a performance issue of the implementation. And it doesn't work well with ref and relref.

@sagarbehere
Copy link
Contributor Author

And it doesn't work well with ref and relref

Okay, let me think more about this. I'll try asking the author of that blog post if there is a better way to do it that works with ref and relref.

I'm afraid there will be a performance issue of the implementation.

Yes. Previous discussions I found on this topic had the same concern. For example, gohugoio/hugo#8077 (comment)

Just trying to brainstorm some ideas below:

  1. Would there be a way to have this as on option that is disabled by default? Then, only those users who are willing to accept slower performance in order to get backlinks, would turn it on?

  2. I'll also consider if it is possible to do some other preprocessing of the markdown files in python or something, so that the backlinks can be appended to each markdown file before Hugo processes them. That way, Hugo will not have to do anything and there will be no performance issue. A related question to this is: If the preprocessor puts all the backlinks for foo.md in a separate file named e.g. foo-backlinks.md instead of appending the backlinks at the end of foo.md, do you know if Hugo can pick up the content of foo-backlinks.md and append it to foo.md during its rendering process?

  3. Do you know if the render-link.html hook of the Goldmark render could be useful here? For example, if the script in render-link.html creates/adds some link metadata content to an index file each time it sees a link in a markdown file, then it could be much more easy to compute the backlinks for a given file by querying the index.file. Do you think something like this could be possible?

@razonyang
Copy link
Owner

  1. The main reason I'm concerning about is lack of an ideal way to solve it. There are two implementations I found, one is you mentioned above, the other is defining backlinks in front matter(similar to your second point) manually. But the former implementation doesn't work well in multilingual mode, such as {{ ref . (dict "path" "about.md" "lang" "fr") }}, I think it always matches the default language version of page about.md. The later implementation matches pages accurately, but it's a little cumbersome for users.

  2. It is similar to the later implementation I mentioned in point 1.

  3. Yup, this theme uses render-link render links. But I am not sure if it can be used for collecting backlinks.

@razonyang
Copy link
Owner

Update: render-link will not be triggered by ref and relref, so it isn't the right way.

@sagarbehere
Copy link
Contributor Author

sagarbehere commented Jan 10, 2022

Hmm... thank you for thinking about this. I can't think of any other options. So for now, we could close this issue as "will not implement.

I'll try to write a python script that will read the markdown files and append a backlinks section at their end, containing lists of refs/relrefs. This script can be executed before Hugo is executed.. so that Hugo does not need to do anything.. it'll be as if the source files Hugo processes has all the correct backlinks already present in them.

@razonyang
Copy link
Owner

OK, I keep it closed until we found a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants