hugo-theme-bootstrap4-blog
hugo-theme-bootstrap4-blog copied to clipboard
Create relative links only
The distributed web slowly becomes a reality and that's good in my opinion when you take the current hysteria and the rise of censorship into account.
I'm currently in the process of converting my blog so that it will be usable on IPFS (https://ipfs.io/). The main problem is converting all links to be relative to the current page.
In general this can be done with relativeURLs = true
in config.toml but:
- embedded styles with url() are not handled correctly - this happens for my image galleries - I handled it with giving only relative image URLs to the gallery
- the theme has lots of places where absolute URLs get generated - these are not converted back by Hugo
What are the advantages of relative URLs?
- you can view the page on IPFS on any gateway (dweb.link, ipfs.io, cloudflare-ipfs.com, your local IPFS gateway on localhost etc)
- if you eliminate all external dependencies you can even pack you site on a USB stick an view it locally - something what static web pages nearly always were useful for
What's your opinion? Is it worth to go this direction with the theme? I personally end up overwriting most of the theme but I'm o.k. with this.
@fte378 apologies for the late reply. The distributed web is a good thing and I support your exploration in that area, but I have been thinking about this a little bit in the theme context and I'm still unsure. When building the theme I consciously used the absURL
template function because I thought absolute was better or more exact somehow. It's only a handful of places actually:
$ grep -rsI absURL layouts/*
layouts/_default/single.html: "url": {{ . | absURL }}
layouts/_default/baseof.html: <h1 class="blog-title" dir="auto"><a href="{{ .Site.BaseURL | absURL }}" rel="home">{{ .Site.Title | safeHTML }}</a></h1>
layouts/partials/sidebar.html: <li><a href="{{ .URL | absURL }}">{{ .Name }}</a></li>
layouts/partials/cookie-consent.html: policyUrl: {{ . | absURL }},
layouts/robots.txt:Sitemap: {{ "sitemap.xml" | absURL }}
Curiously the 404 template uses relURL
:
$ grep -rsI relURL layouts/*
layouts/404.html: <p>Page not found. Go back <a href="{{ "/" | relURL }}">home</a>.</p>
How does the site-wide relativeURLs
setting affect these template functions?
The places where absUrl is used are not touched again by Hugo. I had to replace them. I'm already done with the conversion since mid-April and it works well.
I even wrote an article about it (German but I think it's understandable even through a translator): https://frank.tegtmeyer.net/2020/04/ipfs-und-mein-blog/
I also used absolute URLs a lot to avoid confusion and downgrading in search engines but I got to a state of mind where I don't care anymore about search engines. Good content eventually wins even when it does nothing regarding SEO.
For me the possibility to "mount" the blog at any URL (including offline use) is a plus.
For the conversion I had to remove the SEO stuff from the headers - there were some things (I think with the images) which I could not get to generate relative URLs.
The problem with the theme is that other users may have completely opposite views about the topic.
Regards, Frank