|
|
@ -0,0 +1,120 @@ |
|
|
|
#lang racket/base |
|
|
|
|
|
|
|
(require racket/system) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Rough ideas/notes |
|
|
|
;; ---------------------------------------------- |
|
|
|
;; TODO layout |
|
|
|
; * head.md (required) |
|
|
|
; * nav.md (required) |
|
|
|
; * footer.md (required) |
|
|
|
;; TODO copy folder (recursive copying) |
|
|
|
; * style.css ;; probably don't need this |
|
|
|
; * images/ |
|
|
|
; * misc/ |
|
|
|
; * pdfs/ |
|
|
|
; * work/ |
|
|
|
; * screenshots/ |
|
|
|
; * pastes/ |
|
|
|
;; TODO convert folder (recursive converting) |
|
|
|
; * root pages |
|
|
|
; * posts |
|
|
|
; * e.g. 2018 |
|
|
|
; * some-post1.md |
|
|
|
; * some-post2.md |
|
|
|
; * some-post3.md |
|
|
|
; * e.g. 2019 |
|
|
|
; * some-post1.md |
|
|
|
; * some-post2.md |
|
|
|
; * some-post3.md |
|
|
|
;; ---------------------------------------------- |
|
|
|
;;done |
|
|
|
(define cmds '("init" "build" "serve" "clean")) |
|
|
|
|
|
|
|
(define dirs '("output" "layout" "copy" "convert")) |
|
|
|
|
|
|
|
(define layout (map (lambda (x) (string-append (cadr dirs) x)) |
|
|
|
'("header.md" "footer.md"))) |
|
|
|
|
|
|
|
(define-syntax-rule (displayln-format str ...) |
|
|
|
(displayln (format str ...))) |
|
|
|
|
|
|
|
(define (file-create file) |
|
|
|
(if (or (file-exists? file) |
|
|
|
(directory-exists? file)) |
|
|
|
(displayln-format "Cannot create file. '~a' already exists" file) |
|
|
|
(close-output-port (open-output-file file #:exists 'truncate)))) |
|
|
|
|
|
|
|
(define (dir-create dir) |
|
|
|
(if (or (file-exists? dir) |
|
|
|
(directory-exists? dir)) |
|
|
|
(displayln-format "Cannot create directory. '~a' already exists" dir) |
|
|
|
(make-directory dir))) |
|
|
|
|
|
|
|
(define (dirs-missing) |
|
|
|
(filter (lambda (x) (not (directory-exists? x))) |
|
|
|
dirs)) |
|
|
|
|
|
|
|
(define (dirs-missing?) |
|
|
|
(> (length (dirs-missing)) 0)) |
|
|
|
|
|
|
|
(define (files-missing) |
|
|
|
(filter (lambda (x) (not (file-exists? x))) |
|
|
|
layout)) |
|
|
|
|
|
|
|
;; --------------------------------------- |
|
|
|
;; build |
|
|
|
;; --------------------------------------- |
|
|
|
;; In the future, I will need to change `--base-head-level=2` to |
|
|
|
;; `--shift-heading-level-by=2`, because Debian is using an older version of |
|
|
|
;; Pandoc. |
|
|
|
(define (markdown->html file) ;; add destination here |
|
|
|
(let ([cmd "pandoc -s -c /style.css ~a -o ~a --base-header-level=2"] |
|
|
|
[input (format "~a ~a ~a" (car layout) file (cadr layout))] ;; needs full path |
|
|
|
[output (format "~a/~a.html" (car dirs) file)]) ;; needs destination/full path |
|
|
|
(system (format cmd input output)))) |
|
|
|
|
|
|
|
;; TODO |
|
|
|
;(fn build/copy-dirs [] |
|
|
|
|
|
|
|
;; TODO |
|
|
|
(define (build) |
|
|
|
(build/copy) |
|
|
|
(build/convert) |
|
|
|
|
|
|
|
;; --------------------------------------- |
|
|
|
;; init |
|
|
|
;; --------------------------------------- |
|
|
|
(define (init/checker) |
|
|
|
(if (> (length (dirs-missing)) 0) |
|
|
|
|
|
|
|
(define (init/start) |
|
|
|
(for ([dir dirs]) |
|
|
|
(when (not (directory-exists? dir)) |
|
|
|
(displayln-format "Creating '~a' directory..." dir) |
|
|
|
(dir-create dir)))) |
|
|
|
|
|
|
|
(define (init/read-input) |
|
|
|
(let ([input (read-char)]) |
|
|
|
(if (equal? input #\y) |
|
|
|
(init/start) |
|
|
|
(displayln "Cancelled creation of directories")))) |
|
|
|
|
|
|
|
(define (init/prompt) |
|
|
|
(displayln "The following directories will be created:") |
|
|
|
(for ([dir dirs]) |
|
|
|
(when (not (directory-exists? dir)) |
|
|
|
(displayln-format " ~a" dir))) |
|
|
|
(displayln "Do you want to create them? (y/n)") |
|
|
|
;; (flush-output) |
|
|
|
(init/read-input)) |
|
|
|
|
|
|
|
(define (init) |
|
|
|
(if (> (length (dirs-missing)) 0) |
|
|
|
(init/prompt) |
|
|
|
(displayln "Required directories already exist"))) |
|
|
|
|
|
|
|
;; For testing |
|
|
|
(init) |