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

Ugly behavior of PrettyRelativeLinks #53

Closed
TPKato opened this issue Mar 31, 2021 · 2 comments
Closed

Ugly behavior of PrettyRelativeLinks #53

TPKato opened this issue Mar 31, 2021 · 2 comments

Comments

@TPKato
Copy link

TPKato commented Mar 31, 2021

I have a problem with referring my image files with Hugo.
I tried Hugo with the following files.

$ hugo version
hugo v0.83.0-DEV+extended

(It uses go-org v1.4.0.)

content
├── _index.org
├── test-branch
│   ├── _index.org (*1)
│   ├── content1.org (*2)
│   ├── content2.org
│   └── test.png
└── test-leaf
    ├── index.org  (*3)
    └── test-leaf.png

The problem is:

  • (*1) To refer test.png correctly I must write [[./test-branch/test.png]], because [[./test.png]] will be converted as <img src=".././test.png" alt=".././test.png" title=".././test.png" />. I think it is ugly.
  • (*2) To refer test.png, you should write [[./test.png]]. (It might be intuitive but...)
  • (*3) Same as (*1)

Furthermore, to refer content2.org you should write [[./content2]] in content1.org (*2) but [[test-branch/content2]] in _index.org (*1), though these files are in the same directory.
(And for the files in content/ it might be even worse, especially the top URL is not / (e.g. https://example.com/hugo/ instead of https://example.com/).)

I think this behavior of the PrettyRelativeLinks is very ugly and harmful for users.

For (*1) and (*3) I want to write [[./test.png]] so I don't have to change anything when I change the name of the directory, even if I have to write [[../test.png]] for (*2).

FYI: With .md files:

  • (*1) To refer test.png, you should write ![Alt text](./test.png "a title"). (of course)
  • (*2) To refer test.png, you should write ![Alt text](../test.png "a title"). (../ instead of ./)
    It might not be intuitive, but understandable, because the URL for content1.md is .../test-branch/content1/.
  • (*3) To refer test-leaf.png you should write ![Alt text](./test-leaf.png "a title"). (of course)

I think this behavior is reasonable.

@niklasfasching
Copy link
Owner

Interesting. I'll disable pretty links in the next PR to hugo. Looks like #45 doesn't have an easy solution after all.

niklasfasching referenced this issue Apr 11, 2021
Hugo defaults to serving files with pretty urls [1] - this means
`/posts/foo.org` is served at `/posts/foo/`. This works because servers
default to serving index.html when a directory is specified and hugo renders
the post to `/posts/foo/index.html` instead of `/posts/foo.html`. To make
relative links work we need to (1) remove the fake `foo/` subdirectory from
unrooted links and (2) replace any `.org` suffix with `/`.

[1] https://gohugo.io/content-management/urls/#pretty-urls
@niklasfasching
Copy link
Owner

gohugoio/hugo#8410

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
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

2 participants