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

Add support for page backlinks (e.g. .GetBacklinks) #8077

Open
gcushen opened this issue Dec 19, 2020 · 23 comments
Open

Add support for page backlinks (e.g. .GetBacklinks) #8077

gcushen opened this issue Dec 19, 2020 · 23 comments
Labels

Comments

@gcushen
Copy link

gcushen commented Dec 19, 2020

Problem

As far as I can tell, there is currently no user friendly and efficient way to get the set of internal pages that link to a page (aka backlinks) via Hugo's Go templating.

Internal backlinks are really useful to those using Hugo in academia and for research and note taking. It's become one of the top selling points used by popular note taking apps such as Notion and Roam Research.

There is also demand in the community for such capability, for example:

Possible high-level solution

Expose a .GetBacklinks page option which provides a list of Page instances (similar to .GetTerms output) that link to the current page.

@HughP
Copy link

HughP commented Dec 19, 2020

Ok, so I'm not sure what you mean by "back links". I did read the the linked articles... This is only for links inside of the blog, not pingbacks like wordpress, where if another blog mentions your article then you generate a link saying they were talking about your blogpost.

Can we get a few use cases of how people might be interested to use this? I use the tags feature and the related content features. See related content here: https://hughandbecky.us/Becky-CV/publication/2015-narrative-uses-of-utmatin-bare-verb

@davidsneighbour
Copy link
Contributor

Use cases are probably always wiki-like features, where you show which page links to what page. Using tags is certainly a solution, but it will make you have to edit all pages that your new page links to, to add a backlink. While having this done internally would be nice, it might also slow the build process down (for people that do not require that feature). I am pretty sure this can be done with some kind of .scratch functionality.

@iphysresearch
Copy link

iphysresearch commented Dec 22, 2020

Love the new feature "backlinks" or "bidirectional links"! As a heavy fan of Roam research, I am truly looking forward to this!

It's all related to zettelkasten —— knowledge management and note-taking method used in research and study.

@bep
Copy link
Member

bep commented Dec 22, 2020

I understand the "usefulness", but this is in my head currently very hard to do. For this to work you would probably need to render all content in 1 thread before you can do anything else -- which would slow down the build a whole lot.

@NightMachinery
Copy link

@bep If it is an opt-in feature, the slowdown is tolerable. One can turn it off when one is doing experiments requiring fast reload, and turn it back on for the production version. Anyhow, a slow thing is better than nothing.

@lucasew
Copy link

lucasew commented Jun 1, 2021

It can be opt in via the configuration file.

A way to index this is to traverse the files looking for internal link references. If a file changes you can just update the index of that file.

It will require a warm-up on setup to index and because it's opt in if you don't use you can just disable with no penalty.

@sjgknight
Copy link

@gcushen I'm interested in this but not competent to implement. In looking around I've found two people discussing ways of doing this https://gabrielleearnshaw.medium.com/implementing-backlinks-in-a-hugo-website-e548d3d8f0e0 and https://seds.nl/notes/export_org_roam_backlinks_with_gohugo/ (I'm going to play, but I'm not likely to be able to implement). I can imagine academics e.g. being interested in linking projects<->publications<->authors<->news.
Taxonomies/tags can do some of this I think, but it's not quite the same. @apreshill also has an "on this page" which shows the headings for a page, which I assume could be used to show the links https://github.com/rbind/apreshill/search?q=%22on+this+page%22&type= ? Apologies this is just a a link dump .

@lucasew
Copy link

lucasew commented Aug 5, 2021 via email

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@github-actions github-actions bot added the Stale label Aug 20, 2022
@BBaoVanC
Copy link

I still think this is useful, especially for wikis which was mentioned above.

@github-actions github-actions bot removed the Stale label Aug 21, 2022
@kaihendry
Copy link

Zola has backlinks support, it would be good if Hugo has the same feature.

https://twitter.com/20100Prouillet/status/1548430360135929856

@RenaudDev
Copy link

It would be hugely useful for my project. Please make it happen.

@carlklier
Copy link

I want to bump this because I am looking for exactly this. Backlinks are incredibly useful

@bryanwhiting
Copy link

Bumping!

1 similar comment
@sacgov
Copy link

sacgov commented Jun 8, 2023

Bumping!

@Heinrichsgeist
Copy link

Solution proposal (high level):

  • hugo build n collects the "truth about backlinks at n" and generates the "backlinks valid for build n-1"
  • hugo build n+1 collects the "truth about backlinks at n+1" and generates the "backlinks valid for build n"
  • hugo build n+2 collects the "truth about backlinks at n+2" and generates the "backlinks valid for build n+1"
  • ...

Performance should be good, but there's a lack of adequacy: Internal linkage changes will take effect with one build delay.

@Heinrichsgeist
Copy link

Solution proposal (high level):

* hugo build n collects the "truth about backlinks at n" and generates the "backlinks valid for build n-1"

* hugo build n+1 collects the "truth about backlinks at n+1" and generates the "backlinks valid for build n"

* hugo build n+2 collects the "truth about backlinks at n+2" and generates the "backlinks valid for build n+1"

* ...

Performance should be good, but there's a lack of adequacy: Internal linkage changes will take effect with one build delay.

This behaviour could be acceptable, e. g. when performance is no issue, or when there's a high frequency of site updates, or when the ratio of internal linkage changes is low.

@leofujiike
Copy link

How about Quartz? It is compatible with Hugo and comes with support for backlinks and a graph view, and it's easy to use.
Repository: https://github.com/jackyzha0/quartz
Setup Instructions: https://quartz.jzhao.xyz/notes/setup/

@ManuelLevi
Copy link

It would be great to have a native solution to this, instead of a third-party project like quartz.

@bixfrankonis
Copy link

This sort of feature is one of the things that has left me on WordPress, where me and ChatGPT designed a solution using post metadata. My blog basically has no other form of organizing content (no tags, etc.). Internal backlinks is a must for my use case, and I'd consider getting the hell off the ever more monstrous thing that is WordPress and onto a static approach if there were an internal backlinks solution.

@jmooring
Copy link
Member

This uses a relatively simple module to capture and render backlinks.

git clone --single-branch -b hugo-github-issue-8077 https://github.com/jmooring/hugo-testing hugo-github-issue-8077
cd hugo-github-issue-8077
hugo server

Details:
https://github.com/jmooring/hugo-module-backlinks

@unindented
Copy link

This uses a relatively simple module to capture and render backlinks.

git clone --single-branch -b hugo-github-issue-8077 https://github.com/jmooring/hugo-testing hugo-github-issue-8077
cd hugo-github-issue-8077
hugo server

Details: https://github.com/jmooring/hugo-module-backlinks

That's clever! Is there a way to make this work with {{< relref "..." >}} links?

@jmooring
Copy link
Member

@unindented Use the {{% %}} notation when calling the relref shortcode.

[Post 1]({{% relref "post-1" %}})

However, the test site enables Hugo's embedded link render hook (see site configuration), so you shouldn't need to use the relref shortcode anywhere. The relref shortcode was essentially made obsolete when we introduced link render hooks a few years ago.

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

No branches or pull requests