◉ blog menu

SRC lisp :results value raw output 
  (ql:quickload '(:unix-cmd) :silent t) ; =>(:UNIX-CMD) 
  (defpackage :myblog 
    (:use :cl :unix-cmd)
    (:export :main))                    ; =>#<PACKAGE "MYBLOG"> 
  (in-package :myblog)                  ; =>#<PACKAGE "MYBLOG"> 
  
  (defconstant blog-base "biofermin2.github.io/docs/") ; =>BLOG-BASE 
  (defparameter blog-home
    (merge-pathnames blog-base (user-homedir-pathname))) ; =>BLOG-HOME 
  
  (defun get-titles (org-file)
    (with-open-file (in org-file :direction :input)
      (loop :for line = (read-line in nil)
            :while line
            :with titles
            :do (cond ((and (> (length line) 2)
                            (string-equal (subseq line 0 2) "* "))
                       (push (subseq line 2) titles))
                      ((and (> (length line) 3)
                            (string-equal (subseq line 0 3) "** "))
                       (push (subseq line 3) titles)))
            :finally (return (reverse titles))))) ; =>GET-TITLES 
  
  (defun scan (key obj)
    (let ((key-len (length key))
          (start (search key obj)))
      (when start
        (values start (+ start key-len))))) ; =>SCAN 
  
  (defun %s (old new obj)
    (multiple-value-bind (start end)
        (scan old obj)
      (if start
          (let* ((rest (subseq obj end))
                 (result (%s old new rest)))
            (concatenate 'string (subseq obj 0 start) new result))
          obj)))                        ; =>%S 
  
  (defun make-link (html-file)
    (let* ((html-path (merge-pathnames html-file blog-home))
           (html->org (make-pathname :type "org" :defaults html-path))
           (org-file (if (probe-file html->org)
                         html->org
                         (make-pathname :name (%s ".org" ""
                                                  (pathname-name html-file))
                                        :type "org" :defaults html-path)))
           (titles (get-titles org-file)))
      (with-output-to-string (s)
        (loop :initially (format s "** [[./~a][~a]]~%" html-file (string-right-trim
                                                                  '(#\Space #\Tab) (car titles)))
          :for title :in (cdr titles)
          :do (format s " - ~a~%" title))))) ; =>MAKE-LINK 
  
  (defun menu (html-file)
    (cd blog-home) 
      (format t "~{~a~}"
              (mapcar #'(lambda (x) (make-link x))
                      (reverse (ll html-file))))) ; =>MENU 
  ;; (defun menu (html-file)
    ;; (cd blog-home) 
    ;; (with-open-file (s "top-menu.org" :direction :output
    ;;                                   :if-exists :supersede)
    ;;   (format s "~{~a~}"
    ;;           (mapcar #'(lambda (x) (make-link x))
    ;;                   (reverse (ll html-file)))))) ; =>MENU 

  (menu "202?/*.html")
SRC

RESULTS:  2023-04-23 日]
 – COMMENT ROUTINE  2023-04-24 月  06:00  morning routine [/]
 – COMMENT ROUTINE  2023-04-24 月  06:30  days routine [/]
 – COMMENT ROUTINE  2023-04-24 月  20:00  night routine [/]
 – COMMENT ROUTINE Monday routine [/]
 – dpANSのorg文書化 :lisp:
○  2023-03-30 木]
 – 先日のloopのnamedするかしないかでの挙動の違いについて :lisp:
○  2023-03-26 日]
 – loopのおかしな挙動 :lisp:
○  2023-03-24 金]
 – 配列とハッシュテーブルの違い :lisp:
○  2023-02-27 月]
 – 昨日の続き :lisp:
 – janet-langのインストール :lisp:
○  2023-02-26 日]
 – lisptea timeの質問のまとめ :lisp:
○  2023-02-19 日]
 – 湯たんぽ話 :lifehack:
○  2023-02-14 火]
 – the :lisp:
○  2022-12-28 水]
 – 餅つき
○  2022-12-26 月]
 – 千歯扱き初体験 :agriculture:
○  2022-12-17 土]
 – サツマイモ完食 :agriculture:
○  2022-12-13 火]
 – 猫用出入り口を作る :diy:
○  2022-12-10 土]
 – ubuntuの修復作業
○  2022-12-07 水]
 – org-mode復帰
○  2022-12-03]
 – カブの海水漬け :cooking:
○  2022-11-30 水]
 – menu表示機能を作ってみた :dev:
○  2022-11-27 日]
 – 里芋の収穫 :agriculture:
○  2022-11-15 火]
 – チェーンソーを試す :forestry:
○  2022-11-14 月]
 – jsclを入れてみた :lisp:
 – このブログの在り方について
○  2022-10-30 日]
 – 木を切る :forestry:
 – substとsublis :lisp:
○  2022-10-28 金]
 – 木を切る :forestry:
 – 耕運機を頂く :agriculture:
○  2022-10-27 木]
 – awsにlispをインストール :lisp:
○  2022-10-26 水]
 – アスパラガスと人参の播種 :agriculture:
 – ブログ運用での問題点 :lisp:
○  2022-10-24 月]
 – 韮、青紫蘇、南瓜、薩摩芋、落花生、黒豆、青大豆、黒ささげ、ズッキーニ :agriculture:
○  2022-10-20 木]
 – ラッカセイの収穫 :agriculture:
○  2022-10-19 水]
 – クロマメ、アオダイズ、クロササゲ収穫 :agriculture:
○  2022-09-30 金]
 – fusion! :lisp:
○  2022-09-27 火]
 – common lispでの文字列置換2
○  2022-09-16 金]
 – 我が家のlisp本 :lisp:
○  2022-09-14 水]
 – 空芯菜の収穫 :agriculture:
 – common-lispでfizzbuzz :lisp:
○  2022-09-13 火]
 – 最近のlisp系の傾向について思う事。 :lisp:
○  2022-09-12 月]
 – このブログのこれからの在り方 :dev:
○  2022-09-10 土]
 – common lispでの文字列置換 :lisp:
○  2022-09-09 金]
 – なぜmarkdown形式ではなくorg-mode形式で書くのか? :lisp:
○  2022-09-08 木  org-modeによるgithub pagesの作成2
 – あれから 
 – vimによるhtml化
 – emacsでのhtml化
 – emacsの配色設定
 – 最初は
 – org-babelの問題点
 – おわり
○  2022-09-07 水  org-modeでgithub pagesのサイトを作る
 – 個人blogの作成
 – orgファイルのhtml化の方法
 – 問題点