From 0b565afaf9b0f4695833172bbac93e01ac78f771 Mon Sep 17 00:00:00 2001 From: Jason TIAN Date: Sun, 15 Jan 2023 13:03:21 +0800 Subject: [PATCH] draft for #102, to be done... --- .../replace-content-with-keywords-links.html | 26 +++++++++++++++++++ static/csv/keywords-links.csv | 0 2 files changed, 26 insertions(+) create mode 100644 layouts/partials/replace-content-with-keywords-links.html create mode 100644 static/csv/keywords-links.csv diff --git a/layouts/partials/replace-content-with-keywords-links.html b/layouts/partials/replace-content-with-keywords-links.html new file mode 100644 index 0000000..c7c88ac --- /dev/null +++ b/layouts/partials/replace-content-with-keywords-links.html @@ -0,0 +1,26 @@ +{{/* this is used to replace the keywords in content with links + +reference: +- https://discourse.gohugo.io/t/replace-function-when-applied-to-content-displays-html-tags-instead-of-rendering-them/37717 +- https://gohugo.io/templates/data-templates/ +- https://github.com/gohugoio/hugo/issues/1150 +*/}} + +{{ $Content := .Content }} + +{{/* to be fixed... */}} + +{{ $url := "static/csv/keywords-links.csv" }}. +{{ $sep := "," }} +{{ range $i, $r := getCSV $sep $url }} +{{ index $r 0 }} +{{ index $r 1 }} +{{ end }} + +{{ range $topics }} +{{- if (strings.Contains $Content .) -}} +{{ $Content = replace $Content . "." }} +{{ end }} +{{ end }} + +{{ $Content | safeHTML }} \ No newline at end of file diff --git a/static/csv/keywords-links.csv b/static/csv/keywords-links.csv new file mode 100644 index 0000000..e69de29