Best practise for blog publishing

If I publish my whole blog as a directory node every time I write a new post, then my posts end up having many different paths/urls because they will be seen as a filename under the directory hash.

However, each post of course has its own hash, and so I can get around this by linking to /ipfs/post-hash instead – then my links never change and the path is always the same.

Question: when hosting on my domain, if I just link to /ipfs/post-hash then to make that work I essentially have to graft a public ipfs gateway onto my domain. Is that a reasonable thing to do? Or should I use http://ipfs.io/ipfs/post-hash links?

The simple way of setting up a website is to add the entire website to IPFS, then use the root hash.

Quick example:

First create both index.html and firstpost.html and then add them to IPFS

$ ls
firstpost.html  index.html

$ cat firstpost.html
Hello world

$ cat index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
  <a href="./firstpost.html">First Post</a>
</body>
</html>

$ ipfs add -r .
added QmePw8gVcBMb8x6kAep6aMBAX23hCSk6iZW3i9VKkiFhu1 tmp.YoFFC4RGK0/firstpost.html
added Qmf7mg1Xi1YH7Xeds6J7Dhz8SRvkMRBkP9LTwWSbedwK4h tmp.YoFFC4RGK0/index.html
added QmdKpDPHpNx6cLUWViHXLAzAwnKspYf7iJUMmr8HPcSdBQ tmp.YoFFC4RGK0

The root hash is the last hash, QmdKpDPHpNx6cLUWViHXLAzAwnKspYf7iJUMmr8HPcSdBQ. This is the one you will send people. Since firstpost.html is relatively linked, it’ll work to resolve it when people click on the link.

Now, let’s say we add another post to our example and then add to IPFS again

$ cat secondpost.html
Second post

$ cat index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
  <a href="./firstpost.html">First Post</a>
  <a href="./secondpost.html">Second Post</a>
</body>
</html>

$ ipfs add -r .
added QmePw8gVcBMb8x6kAep6aMBAX23hCSk6iZW3i9VKkiFhu1 tmp.YoFFC4RGK0/firstpost.html
added QmXsDomV8zSZJ8tSsCiLTdWVV5k8ph3jKdSqfKJhk2P8pW tmp.YoFFC4RGK0/index.html
added QmYQTFLHtocZcbEphEpLbhRd19aj8bpKUR3q5pm2QBJZxR tmp.YoFFC4RGK0/secondpost.html
added QmUeWXkXy6ygANqw4NKnSYf41Mtn35LV6SupgHQdZ89UNt tmp.YoFFC4RGK0

When adding the site now, secondpost.html is a new file and index.html has changed, so the root hash is now instead QmUeWXkXy6ygANqw4NKnSYf41Mtn35LV6SupgHQdZ89UNt. This is again the hash you would send people.

But sending everyone the new hash gets boring quickly, so you can use DNS to make people be able to just reload the page instead.

So set A records of example.com to point to a IPFS gateway (you can use our public gateways if you want, get the IP by pinging ipfs.io a couple of times, and set the A records to point to our gateway hosts).

Once you have A records setup, you need to add a TXT record as well, to define which hash to add. This TXT record needs to have the value dnslink=/ipfs/QmUeWXkXy6ygANqw4NKnSYf41Mtn35LV6SupgHQdZ89UNt. That’s the hash the gateway will load when you load your domain.

Hope this explains how it works. Important point is to keep all links and references to other files relative, so it works both when visiting ipfs.io/ipfs/$yourHash and example.com.

2 Likes

The trouble with this approach is that the absolute path to firstpost keeps “changing” (well, not changing, but we add a new one every time there is a new root hash). So, if I want to give out a link to firstpost on IPFS, the link I should give out constantly changes. But people/systems are going to store the link.

So, I would like to use the unchanging /ipfs/post-hash path as the “permalink” because it’s the one that never changes and people can store forever without it ever pointing to something else.

Not sure I understand you correctly. If you want to link to a permanent copy of firstpost.html, use the hash to it. Which, if you look at the example above, never changes, unless you change the contents of the file itself.

I did it this way:
https://gateway.ipfs.io/ipns/QmZJBQBXX98AuTcoR1HBGdbe5Gph74ZBWSgNemBcqPNv1W/exactly-how-to-host-frog-over-ipfs.html