blog

My blog at www.shimmy1996.com

git clone git://git.shimmy1996.com/blog.git
commit 820b015019d881aaf91b6e951b864fc3afa5b68d
parent 87f8a891b5efcb9a440eceb0d0c65bc07e99989e
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date:   Mon, 13 Apr 2020 20:12:41 -0500

Add section on updating DNS records automatically

Diffstat:
Mcontent/posts/2020-04-10-blog-9-from-outer-space.en.md | 17++++++++++++++++-
Mcontent/posts/2020-04-10-blog-9-from-outer-space.zh.md | 17++++++++++++++++-
Morg/2020.org | 30++++++++++++++++++++++++++++--
3 files changed, 60 insertions(+), 4 deletions(-)
diff --git a/content/posts/2020-04-10-blog-9-from-outer-space.en.md b/content/posts/2020-04-10-blog-9-from-outer-space.en.md
@@ -43,7 +43,22 @@ or
 dnslink=/ipns/<ipns-address>
 ```
 
-For instance, you can now access this site using at [`/ipns/shimmy1996.com`](https://ipfs.io/ipns/shimmy1996.com/) (this is a link using the ipfs.io gateway). While not flawless, to me this is a reasonable compromise for now.
+For instance, you can now access this site using at [`/ipns/shimmy1996.com`](https://ipfs.io/ipns/shimmy1996.com/) (this is a link using the ipfs.io gateway). While not flawless, to me this is a reasonable compromise for now. I find find IPFS to be generally faster than IPNS, so using IPFS address with DNSLink probably makes more sense. To avoid manually copy-pasting the IPFS address each time, I added to my blog build script the following to automatically upload website to IPFS and update DNS record (using [DigitalOcean's API](https://developers.digitalocean.com/documentation/v2/#update-a-domain-record)):
+
+```sh
+echo "Uploading to IPFS..."
+hash=$(/usr/bin/ipfs add -Qr "<website-root>")
+
+echo "Updating DNSLink record..."
+token="<digitalocean-api-token>"
+curl -X PUT \
+     -H "Content-Type: application/json" \
+     -H "Authorization: Bearer $token" \
+     -d "{\"data\":\"dnslink=/ipfs/$hash\"}" \
+     "https://api.digitalocean.com/v2/domains/<domain>/records/<record-id>"
+```
+
+Record ID for DNS records on DigitalOcean can also be [retrieved via their API](https://developers.digitalocean.com/documentation/v2/#list-all-domain-records). You may need to add `?page=2` or later to the request to find the record you want.
 
 Do note that like using any offline HTML files, we need to use relative URLs in the generated web pages. In Hugo, this can be achieved by setting
 
diff --git a/content/posts/2020-04-10-blog-9-from-outer-space.zh.md b/content/posts/2020-04-10-blog-9-from-outer-space.zh.md
@@ -42,7 +42,22 @@ dnslink=/ipfs/<网站根目录哈希>
 dnslink=/ipns/<ipns-地址>
 ```
 
-例如本站就可以通过[/ipns/shimmy1996.com](https://ipfs.io/ipns/shimmy1996.com/)(该链接使用ipfs.io架设的公共网关)来访问。虽然算不上是一个完全没有缺点的办法,但对我来说这是个合理的妥协。
+例如本站就可以通过[/ipns/shimmy1996.com](https://ipfs.io/ipns/shimmy1996.com/)(该链接使用ipfs.io架设的公共网关)来访问。虽然算不上是一个完全没有缺点的办法,但对我来说这是个合理的妥协。我发现IPFS通常比IPNS快,所以在DNSLink里用IPFS地址应该更加合适。为了避免每次手动复制粘贴,我在博客构建脚本中添加了以下内容以自动将网站上传到IPFS并更新DNS记录(使用[DigitalOcean的API](https://developers.digitalocean.com/documentation/v2/#update-a-domain-record)):
+
+```sh
+echo "上传网站至IPFS..."
+hash=$(/usr/bin/ipfs add -Qr "<网站根目录>")
+
+echo "更新 DNSLink 记录..."
+token="<digitalocean-api-令牌>"
+curl -X PUT \
+     -H "Content-Type: application/json" \
+     -H "Authorization: Bearer $token" \
+     -d "{\"data\":\"dnslink=/ipfs/$hash\"}" \
+     "https://api.digitalocean.com/v2/domains/<域名>/records/<记录-id>"
+```
+
+DigitalOcean上DNS记录的记录ID也可以通过[其API取回](https://developers.digitalocean.com/documentation/v2/#list-all-domain-records),不过你可能需要在请求中增加`?page=2`或更后面的页码才能找到你想要更新的记录。
 
 对了,还需要注意的是,正如同使用任何脱机HTML文件时一样,我们需要在生成的网页中使用相对链接。在Hugo中,这可以通过在`config.toml`中加入
 
diff --git a/org/2020.org b/org/2020.org
@@ -361,7 +361,20 @@ or
 #+begin_example
   dnslink=/ipns/<ipns-address>
 #+end_example
-For instance, you can now access this site using at [[https://ipfs.io/ipns/shimmy1996.com/][=/ipns/shimmy1996.com=]] (this is a link using the ipfs.io gateway). While not flawless, to me this is a reasonable compromise for now.
+For instance, you can now access this site using at [[https://ipfs.io/ipns/shimmy1996.com/][=/ipns/shimmy1996.com=]] (this is a link using the ipfs.io gateway). While not flawless, to me this is a reasonable compromise for now. I find find IPFS to be generally faster than IPNS, so using IPFS address with DNSLink probably makes more sense. To avoid manually copy-pasting the IPFS address each time, I added to my blog build script the following to automatically upload website to IPFS and update DNS record (using [[https://developers.digitalocean.com/documentation/v2/#update-a-domain-record][DigitalOcean's API]]):
+#+BEGIN_SRC sh
+  echo "Uploading to IPFS..."
+  hash=$(/usr/bin/ipfs add -Qr "<website-root>")
+
+  echo "Updating DNSLink record..."
+  token="<digitalocean-api-token>"
+  curl -X PUT \
+       -H "Content-Type: application/json" \
+       -H "Authorization: Bearer $token" \
+       -d "{\"data\":\"dnslink=/ipfs/$hash\"}" \
+       "https://api.digitalocean.com/v2/domains/<domain>/records/<record-id>"
+#+END_SRC
+Record ID for DNS records on DigitalOcean can also be [[https://developers.digitalocean.com/documentation/v2/#list-all-domain-records][retrieved via their API]]. You may need to add =?page=2= or later to the request to find the record you want.
 
 Do note that like using any offline HTML files, we need to use relative URLs in the generated web pages. In Hugo, this can be achieved by setting
 #+BEGIN_SRC toml
@@ -409,7 +422,20 @@ IPFS的不少方面都可以在过去的项目中看到踪影,例如BitTorrent
 #+begin_example
   dnslink=/ipns/<ipns-地址>
 #+end_example
-例如本站就可以通过[[https://ipfs.io/ipns/shimmy1996.com/][/ipns/shimmy1996.com]](该链接使用ipfs.io架设的公共网关)来访问。虽然算不上是一个完全没有缺点的办法,但对我来说这是个合理的妥协。
+例如本站就可以通过[[https://ipfs.io/ipns/shimmy1996.com/][/ipns/shimmy1996.com]](该链接使用ipfs.io架设的公共网关)来访问。虽然算不上是一个完全没有缺点的办法,但对我来说这是个合理的妥协。我发现IPFS通常比IPNS快,所以在DNSLink里用IPFS地址应该更加合适。为了避免每次手动复制粘贴,我在博客构建脚本中添加了以下内容以自动将网站上传到IPFS并更新DNS记录(使用[[https://developers.digitalocean.com/documentation/v2/#update-a-domain-record][DigitalOcean的API]]):
+#+BEGIN_SRC sh
+  echo "上传网站至IPFS..."
+  hash=$(/usr/bin/ipfs add -Qr "<网站根目录>")
+
+  echo "更新 DNSLink 记录..."
+  token="<digitalocean-api-令牌>"
+  curl -X PUT \
+       -H "Content-Type: application/json" \
+       -H "Authorization: Bearer $token" \
+       -d "{\"data\":\"dnslink=/ipfs/$hash\"}" \
+       "https://api.digitalocean.com/v2/domains/<域名>/records/<记录-id>"
+#+END_SRC
+DigitalOcean上DNS记录的记录ID也可以通过[[https://developers.digitalocean.com/documentation/v2/#list-all-domain-records][其API取回]],不过你可能需要在请求中增加=?page=2=或更后面的页码才能找到你想要更新的记录。
 
 对了,还需要注意的是,正如同使用任何脱机HTML文件时一样,我们需要在生成的网页中使用相对链接。在Hugo中,这可以通过在=config.toml=中加入
 #+BEGIN_SRC toml