;; given a dir
;; go thru each html file
;; grab all the link with thumbnail
;; you got two parts
;; one is a file path
;; the other is a image file path
;; <li><a href="glove80_keyboard.html"><img src="i2/glove80/glove80_keyboard_20230126_599-s250.jpg" alt="thumbnail" />Glove80</a>📶 👍</li>
;; build a hashtable, key is the file path, value is image path
;; then, go thru hashtable, for each key, open it, insert the image path as meta tag, aka twitter card
(defvarxah-thumbnail-links-tablenil"Each key is a file path, and value is a image file path. both are full path.")
(setqxah-thumbnail-links-table (make-hash-table:test 'equal))
;; (clrhash xah-thumbnail-links-table)
(defunxah-walk-dir-x (BaseDir)
"Walk a dir BaseDir, and for each html file function Xfunc on it.
Created: 2024-07-24
Version: 2024-07-24"
(let (xpathsxfilepath)
(setqxpaths (directory-files-recursivelyBaseDir".+\.html$"))
(mapc 'xah-build-hashtablexpaths)))
(defunxah-build-hashtable (Fpath)
"for each thumbnail link in Fpath, push it to hashtable `xah-thumbnail-links-table'.
Created: 2024-07-24
Version: 2024-07-24"
(let ()
;; open the file, goto top, search for a pattern like this
;; <li><a href="glove80_keyboard.html"><img src="i2/glove80/glove80_keyboard_20230126_599-s250.jpg" alt="thumbnail" />Glove80</a>
;; then, grab both links
;; make relative link to full path
;; add file path to hash, with image path as value
(with-temp-buffer
(insert-file-contentsFpath)
(goto-char (point-min))
(while;; <li><a href="glove80_keyboard.html"><img src="i2/glove80/glove80_keyboard_20230126_599-s250.jpg" alt="thumbnail" />Glove80</a>
(re-search-forward"<li><a href=\"\\([^\"]+\\)\"><img src=\"\\([^\"]+\\)\" alt=\"thumbnail\" />\\([^<]+\\)</a>"nilt)
(puthash
(expand-file-name
(match-string 1) (file-name-directoryFpath))
(expand-file-name
(match-string 2) (file-name-directoryFpath))
xah-thumbnail-links-table)))))
;; HHHH---------------------------------------------------
;; (xah-walk-dir-x "c:/Users/xah/web/xahlee_info/kbd/")
;; (hash-table-count xah-thumbnail-links-table)
;; (xah-print-hash xah-thumbnail-links-table)
(xah-build-hashtable"C:/Users/xah/web/xahlee_info/kbd/ergonomic_keyboards_index.html")
;; HHHH---------------------------------------------------
;; now we have built a hashtable.
;; now, go thru the hashtable,
;; for each key, open the file
;; insert the value, to the top of the page
(maphash
(lambda (xkeyxval)
(with-temp-buffer
(insert-file-contentsxkey)
(goto-char (point-min))
(search-forward"<title>")
(goto-char (match-beginning 0))
(insertxval"\n")
;; <meta name="twitter:card" content="summary" />
;; <meta name="twitter:title" content="something" />
;; <meta name="twitter:image" content="https://xahlee.info/bfS8V.jpg" />
;; <meta name="xah:thumbnail" content="https://xahlee.info/bfS8V.jpg" />
))
xah-thumbnail-links-table)