;;; adventuresintechland.el --- my personal CMS -*- lexical-binding: t -*- ;;; package --- Summary ;;; Commentary: ;; TODO ;; use defvar and defconst to declare things ;; the way this should work is ;; 1) I type the contents in a buffer ;; 2) I call the dailyIndex function ;; 3) it inserts the buffer contents into the index ;; 4) it creates the RSS item from the first paragraph (I need to itendify it) ;; 5) it updates the daytracker ;; 6) boom ;; ;; that way, I can focus back on html/css, write about that, including the web engineer thing ;; and that's more fun. ;;; Code: (setq debug-on-error t) ;;;;;;;;;;;;;;;;;;;;;;;;; ;;; constants (defconst jc-repositoryPath "/Users/suzume/Documents/Repositories/brandelune.github.io/") (defconst jc-dayTrackerPath (concat jc-repositoryPath "dayTracker.txt")) (defconst jc-rssFile (concat jc-repositoryPath "adventuresintechland.xml")) (defconst jc-indexPath (concat jc-repositoryPath "index.html")) (defconst jc-tomorrowFile (concat jc-repositoryPath "tomorrow.html")) (defconst jc-tomorrow "tomorrow") (defconst jc-ghPagesURL "https://github.com/brandelune/brandelune.github.io/commits/gh-pages") (defconst jc-siteRoot "https://github.com/brandelune/brandelune.github.io/") (defconst jc-faviconURL "https://brandelune.github.io/favicon/") (defconst jc-rssReferences "\"rss") (defconst jc-baseCSSLink "../../adventuresintechland.css") (defconst jc-dailyCSSLink "./adventuresintechland.css") (defconst jc-todayNavigationContents "

%2$s index gh-pages todo %4$s

") (defconst jc-todayHeaderContents " %1$s ") (defconst jc-todayTemplateContents "%1$s %2$s

Adventures in Tech Land. Season %7$s. Episode %8$s

%4$s %9$s

%3$s, %10$sth day

%5$s

%6$s

%2$s ") (defconst jc-myRSSTemplate " %1$s https://brandelune.github.io/%2$s/index.html https://brandelune.github.io/%2$s/index.html %3$s %4$s ") ;;; variables (defvar jc-lastdayList) (defvar jc-lastdayLink) (defvar jc-lastdayDate) (defvar jc-todayList) (defvar jc-todayHeader) (defvar jc-todayTemplate) (defvar jc-todayNavigation) (defvar jc-todayPath) (defvar jc-todayIndex) (defvar jc-todayDate) (defvar jc-seasonNumber) (defvar jc-seasonEpisode) (defvar jc-totalDays) (defvar jc-newDayTracker) (defvar monthMaxDay) ;;;;;;;;;;;;;;;;;;;;;;;;; (defun dailyIndex (today lastday title subtitle firstpar) "Create an html file for TODAY with LASTDAY TITLE SUBTITLE FIRSTPAR. The contents has to be filled manually, later." ;; Create values for the new index, based on yesterday's values in dayTracker.txt. (save-current-buffer (set-buffer (find-file-noselect jc-dayTrackerPath)) (goto-char (point-min)) (search-forward-regexp "\\([0-9]*\\.[0-9]*\\) \\([0-9]*\\) \\([0-9]*\\) \\([0-9]*\\)") (setq jc-lastdayDate (cl-fourth (decode-time (string-to-number (match-string 1)))) seasonNumber (match-string 2) totalDays (string-to-number (match-string 3)) newTotalDays (+ 1 totalDays) currentEpisode (string-to-number (match-string 4)) newSeasonEpisode (+ 1 currentEpisode)) (kill-buffer)) ;; Input data (interactive (list (read-number "Date: " (cl-fourth (decode-time (float-time)))) (read-number "Previous date: " jc-lastdayDate) (read-string "Title: " ) (read-string "Sub-title: ") (read-string "First paragraph: "))) ;; Create data for last day (setq jc-lastdayList (myDate lastday) jc-lastday (concat (my0Padding (cl-second jc-lastdayList)) (my0Padding (cl-third jc-lastdayList))) jc-lastdayLink (concat (file-name-as-directory "../../../") (file-name-as-directory (number-to-string (cl-first jc-lastdayList))) (file-name-as-directory (my0Padding (cl-second jc-lastdayList))) (file-name-as-directory (my0Padding (cl-third jc-lastdayList))) "index.html") jc-lastdayIndex (concat (file-name-as-directory jc-repositoryPath) (file-name-as-directory (number-to-string (cl-first jc-lastdayList))) (file-name-as-directory (my0Padding (cl-second jc-lastdayList))) (file-name-as-directory (my0Padding (cl-third jc-lastdayList))) "index.html")) ;; Create data for today (setq jc-todayList (myDate today) jc-todaySubPath (concat (file-name-as-directory (number-to-string (cl-first jc-todayList))) (file-name-as-directory (my0Padding (cl-second jc-todayList))) (my0Padding (cl-third jc-todayList))) jc-todayPath (concat (file-name-as-directory jc-repositoryPath) (file-name-as-directory jc-todaySubPath)) jc-todayRelativeIndex (concat (file-name-as-directory "../../../") (file-name-as-directory jc-todaySubPath) "index.html") jc-todayIndex (concat (file-name-as-directory jc-todayPath) "index.html") jc-todayDate (concat (number-to-string (cl-first jc-todayList)) "/" (my0Padding (cl-second jc-todayList)) "/" (my0Padding (cl-third jc-todayList))) jc-todayLinkName (concat (my0Padding (cl-second jc-todayList)) (my0Padding (cl-third jc-todayList)))) ;; Create navigation (setq jc-todayNavigation (format jc-todayNavigationContents jc-lastdayLink ;; 1$ jc-lastday ;; 2$ jc-ghPagesURL ;; 3$ jc-tomorrow ;; 4$ )) ;; Create contents (setq jc-todayHeader (format jc-todayHeaderContents title ;; 1$ jc-baseCSSLink ;; 2$ jc-dailyCSSLink ;; 3$ jc-faviconURL ;; 4$ )) ;; Create today's template (setq jc-todayTemplate (format jc-todayTemplateContents jc-todayHeader ;; 1$ jc-todayNavigation ;; 2$ jc-todayDate ;; 3$ title ;; 4$ subtitle ;; 5$ firstpar ;; 6$ seasonNumber ;; 7$ jc-seasonEpisode ;; 8$ jc-rssReferences ;; 9$ jc-totalDays ;; 10$ )) (make-directory jc-todayPath t) (myInsert jc-todayTemplate "" jc-todayIndex) (myInsert "" "" jc-dailyCSSLink) (myDailyRSSItem title today firstpar) ;; Update the dayTracker data (save-current-buffer (set-buffer (find-file-noselect jc-dayTrackerPath)) (goto-char (point-min)) (insert (format "%s %s %s %s\n" (float-time) seasonNumber jc-totalDays jc-seasonEpisode)) (save-buffer) (kill-buffer)) ;; update the previous page (setq jc-todayDayAnchor (concat "" jc-todayLinkName "")) (myReplace jc-tomorrow jc-todayDayAnchor jc-lastdayIndex) ;; update the root index ;; 1. replace the link to the "last day" update1 (let* ((oldLastDayHref (concat "last day")) (newLastDayHref (concat "last day"))) (myReplace oldLastDayHref newLastDayHref jc-indexPath)) ;; 2. replace the number of documented days update2 (let* ((oldTotaDaysH2 (format "

Logbook, %1$s documented days

" (number-to-string totalDays))) (newTotalDaysH2 (format "

Logbook, %1$s documented days

" (number-to-string newTotalDays)))) (myReplace oldTotaDaysH2 newTotalDaysH2 jc-indexPath)) ;; 3. replace the season and episode number update3 (let* ((oldSeasonDataH3 (format "

Season %1$s, %2$s episodes

" seasonNumber currentEpisode)) (newSeasonDataH3 (format "

Season %1$s, %2$s episodes

" seasonNumber newSeasonEpisode))) (myReplace oldSeasonDataH3 newSeasonDataH3 jc-indexPath)) ;; 4. add a link to the episode index update 4 (let* ((update4Marker "