;;; 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 "")
(defconst jc-baseCSSLink "../../adventuresintechland.css")
(defconst jc-dailyCSSLink "./adventuresintechland.css")
(defconst jc-todayNavigationContents "
"
(number-to-string newTotalDays))))
(myReplace
oldTotaDaysH2
newTotalDaysH2
jc-indexPath))
;; 3. replace the season and episode number update3
(let* ((oldSeasonDataH3 (format "
"
seasonNumber
newSeasonEpisode)))
(myReplace
oldSeasonDataH3
newSeasonDataH3
jc-indexPath))
;; 4. add a link to the episode index update 4
(let* ((update4Marker "
"
jc-todaySubPath
newTotalDays
(substring jc-todaySubPath 2)
title
)))
(myReplace
update4Marker
mainIndexTodayLiHref
jc-indexPath))
;; update the tomorrow file with the new "last day"
(let* ((oldLastDayHref (concat "last day"))
(newLastDayHref (concat "last day")))
(myReplace
oldLastDayHref
newLastDayHref
jc-tomorrowFile))
;; open index file for completion
(find-file jc-todayIndex)
)
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun myDailyRSSItem (title date desc)
"Insert the daily RSS feed with TITLE DATE and DESC."
;;;; TODO add default value for link
(interactive (list
(read-string "Title: ")
(read-number "Date: " (cl-fourth (decode-time (float-time) t)))
(read-string "Description: ")))
(let* ((jc-myRSSTemplateContents (format jc-myRSSTemplate
title ;; 1$
(cl-fifth (myDate date)) ;; 2$
(cl-fourth (myDate date)) ;; 3$
desc ;; 4$
)))
(myInsert
jc-myRSSTemplateContents
""
jc-rssFile)
))
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ManageDailyEntry ()
"Create the current page, update the main index, the RSS feed, the previous page."
)
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my0Padding (number)
"Add a 0 string to one digit NUMBER.
This is used here to represent dates as in 01/01/2021"
;; string-pad "string" "length of padding" "thing to pad with" "pad from start if t"
(string-pad (number-to-string number) 2 48 t))
;; old code
;; (if (< number 10)
;; (format "0%s" number)
;; (number-to-string number)))
;; (my0Padding 3) -> "03"
;; (my0Padding 10) -> "10"
;; TODO add option to "number-to-string" so that the padding can happen there
;; // Defined in ~/Documents/Code/emacs/src/data.c
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun myDate (day)
"Create a plausible (year month DAY) list.
Since I only enter a date for the current entry, I must compute the
previous day and the next days according to what's plausible. It is
expected that I enter a possible date."
;;;; TODO add error tests
;;;; (myDate 29) in February 2024, leap year, returns something like
;;;; (2024 2 29 "Sun, 29 Feb 2024 15:02:03 UT" "2024/2/29")
(let* (
(Today (decode-time (float-time)))
(thisMonth (cl-fifth Today))
(nextMonth (if (= 12 thisMonth)
1
(+ thisMonth 1)))
(lastMonth (if (= 1 thisMonth)
12
(- thisMonth 1)))
(thisYear (cl-sixth Today))
(nextYear (+ thisYear 1))
(lastYear (- thisYear 1))
(monthMaxDay
(cond
((member thisMonth '(1 3 5 7 8 10 12)) 31)
((member thisMonth '(4 6 9 11)) 30)
((and (= 2 thisMonth)
(= 0 (mod (cl-sixth (decode-time (float-time))) 4))) 29)
(t 28)))
(myDay (if (> day monthMaxDay) monthMaxDay day))
(dateDifference (- (cl-fourth Today) (abs myDay)))
(myMonth (cond ((> 24 (abs dateDifference)) thisMonth)
((natnump dateDifference) nextMonth)
(t lastMonth)))
(myYear (cond ((= myMonth thisMonth) thisYear)
((and (= myMonth nextMonth) (= myMonth 1)) nextYear)
(t lastYear)))
(rssDate (concat (format-time-string "%a, " (current-time) t)
(number-to-string myDay)
(format-time-string " %b %Y %H:%m:%S UT" (current-time) t)))
(linkDate (format "%1$s/%2$s/%3$s" myYear (my0Padding myMonth) (my0Padding myDay))))
(list myYear myMonth myDay rssDate linkDate)))
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun myInsert (myText myMarker myFile)
"Insert MYTEXT at MYMARKER in MYFILE.
This is used to insert the RSS part of the feed for that day
at the end of the file, before the closing headers."
(save-current-buffer
;; Record which buffer is current; execute BODY; make that buffer current.
(set-buffer (find-file-noselect myFile))
;; Make buffer BUFFER-OR-NAME current for editing operations.
;; Read file FILENAME into a buffer and return the buffer.
(goto-char (point-min))
;; Set point to POSITION, a number or marker.
;; Return the minimum permissible value of point in the current buffer.
(if (not (search-forward myMarker nil t))
;; Search forward from point for STRING.
(progn
(kill-buffer)
(user-error (format "%s was not found" myMarker)))
;; user-error seems to abort the rest of the progn, hence the need to put kill-buffer above
(progn
(goto-char (point-min))
(goto-char (- (search-forward myMarker) (length myMarker)))
(insert myText)
(indent-region (point-min) (point-max))
;; not sure I want to indent if I use
blocks in the inserted strings
(save-buffer)
(kill-buffer)))))
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun myReplace (fromString toString myFile)
"Replace fromString with toString in MYFILE."
(save-current-buffer
;; Record which buffer is current; execute BODY; make that buffer current.
(set-buffer (find-file-noselect myFile))
;; Make buffer BUFFER-OR-NAME current for editing operations.
;; Read file FILENAME into a buffer and return the buffer.
(goto-char (point-min))
;; Set point to POSITION, a number or marker.
;; Return the minimum permissible value of point in the current buffer.
(if (not (search-forward fromString nil t))
;; Search forward from point for STRING.
(progn
(kill-buffer)
(user-error (format "%s was not found" fromString)))
;; user-error seems to abort the rest of the progn, hence the need to put kill-buffer above
(progn
(goto-char (point-min))
(replace-string fromString toString)
(save-buffer)
(kill-buffer)))))
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun narrowToEditZone ()
"Narrow the index page to the area to edit."
;;;; search id = episode
;;;; goto beginning of line
;;;; set mark
;;;; search id = first sub-title item
;;;; goto to end of line
;;;; narrow-to-region
)
;;;;;;;;;;;;;;;;;;;;;;;;;
(provide 'adventuresintechland)
;;; adventuresintechland.el ends here