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

Problem with internal links and the ref shortcut #51

Closed
pprevos opened this issue Mar 24, 2021 · 8 comments
Closed

Problem with internal links and the ref shortcut #51

pprevos opened this issue Mar 24, 2021 · 8 comments

Comments

@pprevos
Copy link

pprevos commented Mar 24, 2021

Internal links stopped working (Hugo version: hugo v0.81.0+extended linux/amd64 BuildDate=unknown).

I use {{< ref filename.org >}} for internal links. For some reason, Hugo now adds ../ to the front of the HTML link.

{{< ref filename.org >}} resolves properly to https://baseurl/filename/

But when I surround it with square brackets, it goes wrong:

[[{{< ref filename.org >}}][link text]] resolves to ../https://baseurl/filename/.

Everything works fine when using Markdown.

@niklasfasching
Copy link
Owner

niklasfasching commented Mar 28, 2021

Interesting!
Apparently hugo replaces shortcodes with placeholders before sending the markup to the renderer.

To go-org [[{{< ref filename.org >}}][link text]] looks like [[HAHAHUGOSHORTCODE-s0-HBHB][link text]].
This conflicts with the recent introduction of pretty relative links, which tries to be clever and rewrites link urls to make relative links work with hugo pretty urls.

I guess we could just not prettify links starting with HAHAHUGOSHORTCODE. Maybe there's a better solution - I'll think about it some more first.

In the meantime things should work if you use [[filename.org][link text]] instead of {{ref}}. I guess only for simple cases - but maybe it would make more sense to support all common cases in that format instead of adding the shortcode workaround

TLDR: Try [[filename.org][link text]]

@pprevos
Copy link
Author

pprevos commented Mar 28, 2021

Thanks for looking into this issue.

Using [[filename.org][link text]] works only without extension and when the post slug is the same as the filename. Ideally, proper Org Mode file links should be resolved.

Shortcodes have the advantage that Hugo searches for the file if it is not in the same folder and resolves to the slug instead of the filename.

Interestingly, '[[{{% ref markdown %}}][test]]` works as it used to.

The Hugo documentation states that "The < character indicates that the shortcode’s inner content does not need further rendering."

I could easily do a search and replace across my sites.

@niklasfasching
Copy link
Owner

Makes sense, thx for the explanation.
If replacing is an option I'd prefer that to keep the amount of hugo specific code in go-org to a minimum. If you run into any problems with that just re-open / comment and I'll add the pretty url exception for HAHAHUGOSHORTCODE. Closing for now

@pprevos
Copy link
Author

pprevos commented Mar 29, 2021

I replaced all shortcodes and it seems to work.

bep pushed a commit to gohugoio/hugo that referenced this issue Apr 12, 2021
go-org PrettyRelativeLinks rewrites relative org links by
- adding `../` in front
- removing any `.org` suffix

This was meant to play well with hugo pretty urls (which pretty much renders
posts in a subdirectory without the file suffix) and allow use of normal org
file links to reference other posts.

There's a lot of edge cases I didn't consider and multiple bug reports in
go-org [1] later I don't think the complexity of handling those edge cases is
worth it - so let's disable it.

[1]
- niklasfasching/go-org#53
- niklasfasching/go-org@5dadf8c (comment)
- niklasfasching/go-org#51
@pprevos
Copy link
Author

pprevos commented May 9, 2021

Hi Niklas,

I just published a detailed blog post on how to use native Org-Mode support in Hugo to publish websites: https://lucidmanager.org/productivity/create-websites-with-org-mode-and-hugo/

Thanks for maintaining go-org.

Peter

@natrys
Copy link

natrys commented Apr 16, 2022

Hi @pprevos , mind if I ask if you got relative linking to static/ working without sacrificing image preview?

I am writing some R code, I am asking it to produce plots by doing something like:

#+begin_src R :results graphics file :output-dir "../../static/plots/" :file test.png
library(ggplot2)
....
#+end_src

This way I can see generated plot right in org buffer which is very useful, but generated image source still has the /static/ part in it which, as you said in the blogpost, hugo for some reason insists on stripping in the published output.


Also would like to ask @niklasfasching, could the above situation be handled unrelated to the broken PrettyRelativeLinks feature? Maybe as special case only for stripping assetDir fragment from the relative url if it exists? Failing that, do you know of any way assetDir top level could be stopped from being stripped in the published output by Hugo?

@natrys
Copy link

natrys commented Apr 16, 2022

Sigh, right after I finally ask for help, I stumble upon the answer. I still don't understand modules, but this did the job:

[[module.mounts]]
  source="static"
  target="static/static"
  includeFiles = ["plots/*"]

This way, hugo now preserves the top-level static/, and both preview and publish works.

@pprevos
Copy link
Author

pprevos commented Apr 16, 2022

This is an issue for Hugo both in Org mode and Markdown, so it is a Hugo issue, not specific to go-org.

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

3 participants