]> git.eshelyaron.com Git - esy-publish.git/commitdiff
add canonical tags to all html pages
authorEshel Yaron <me@eshelyaron.com>
Sun, 2 Apr 2023 06:32:28 +0000 (09:32 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 2 Apr 2023 06:32:28 +0000 (09:32 +0300)
publish.el

index 63d6267aadec2f2ffbdeba646081d950f098c683..e738fe325514a676ae860fde61de676858c5d66a 100644 (file)
     (with-current-buffer (find-file-noselect (expand-file-name "index.org" dir))
       (org-update-all-dblocks))))
 
+(defun esy/publish-add-canonical-tags (_plist)
+  (dolist (file (directory-files-recursively esy/publish-out-directory
+                                             (rx ".html" eos)))
+    (with-current-buffer (find-file-noselect file)
+      (when (search-forward "<!-- insert canonical tag here -->" nil t)
+        (replace-match (format "<link rel=\"canonical\" href=\"%s\" />"
+                               (concat "https://eshelyaron.com/"
+                                       (file-relative-name file esy/publish-out-directory)))
+                       nil t))
+      (basic-save-buffer))))
+
 (defun esy/publish-completion-function (plist)
+  (esy/publish-add-canonical-tags plist)
   (esy/publish-posts plist)
   (esy/publish-sitemap plist))
 
                       :html-head       (esy/dom-to-string '(link ((rel . "stylesheet")
                                                                   (href . "/style.css")
                                                                   (type . "text/css"))))
-                      :html-head-extra (esy/dom-to-string '(link ((rel . "alternate")
-                                                                  (href . "/rss.xml")
-                                                                  (type . "application/rss+xml")
-                                                                  (title . "RSS feed of eshelyaron.com"))))
+                      :html-head-extra (concat (esy/dom-to-string
+                                                '(link ((rel . "alternate")
+                                                        (href . "/rss.xml")
+                                                        (type . "application/rss+xml")
+                                                        (title . "RSS feed of eshelyaron.com"))))
+                                               "\n<!-- insert canonical tag here -->")
                       :html-preamble-format
                       (list
                        (list