Skip to content

Commit

Permalink
release it
Browse files Browse the repository at this point in the history
  • Loading branch information
Memorytaco committed Oct 21, 2018
1 parent 55b6c66 commit eda3c17
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 154 deletions.
8 changes: 3 additions & 5 deletions Flax/asset.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
;; This is used to cp all resource to destination

(define-module (Flax asset)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9) ;;record type
Expand Down Expand Up @@ -39,17 +37,17 @@
(let ((src-file-name (string-append src-path "/" src-tree))
(dest-file-path (string-append prefix "/" src-tree)))
(if (is-directory? src-file-name)
(mkdir dest-file-path)
(mkdir-p dest-file-path)
(copy-file src-file-name dest-file-path)))
(begin (mkdir (string-append prefix "/" (car src-tree)))
(begin (mkdir-p (string-append prefix "/" (car src-tree)))
(map file-tree-move (cdr src-tree)
(repeat-element-of-list (length (cdr src-tree))
(string-append src-path "/" (car src-tree)))
(repeat-element-of-list (length (cdr src-tree))
(string-append prefix "/" (car src-tree)))))))
;;
(define (cp-file-tree src prefix)
(mkdir (get-absolute-path prefix))
(mkdir-p (get-absolute-path prefix))
(file-tree-move (get-file-tree-list src)
(dirname (get-absolute-path src))
(get-absolute-path prefix)))
17 changes: 7 additions & 10 deletions Flax/command/build.scm
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
;; TODO : unfinished file
(define-module (Flax command build)
#:use-module (Flax site)
#:use-module (Flax utils)
#:use-module (ice-9 ftw)
#:use-module (ice-9 r5rs)
#:use-module (ice-9 match)

#:export (show-help
#:export (show-build-help
build))

;; not complete
(define (show-help)
(format #t "Useage:~%")
(format #t "1.~%"))
;; display the build command usage
(define (show-build-help)
(format #t "Useage: flax build <ConfigFileName> ~%")
(format #t "If the <ConfigFileName> is not provided, use \"config.scm\" instead. ~%"))

;;
;; the build command which is invoked by the ui
(define* (build #:key (config-file "config.scm"))
(if (file-exists? (get-absolute-path config-file))
(let ((obj (config-load config-file)))
(if (is-site? obj)
(begin
(build-site obj)
(format #t "~%!!Done!!~%"))
(build-site obj)
(format (current-error-port) "Didn't receive site object !~%Last config expression must be site ~%")))
(begin
(format #t "Coundn't find config file !! ~%expect ~a but got nothing !~%" (basename config-file)))))
16 changes: 10 additions & 6 deletions Flax/page.scm
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
;; the page data type

(define-module (Flax page)
#:use-module (Flax post)
#:use-module (Flax html)
#:use-module (Flax process)

#:use-module (ice-9 regex)
#:use-module (ice-9 match)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
Expand All @@ -18,10 +17,14 @@
write-page
create-writer
page))
;;

;; define the record <page>
;; ~file-name~ is a string
;; ~contents~ is a html code
;; ~contents~ is the page content
;; ~writer~ is the procedure to write the
;; content to disk and the procedure may do
;; some extra job like converting the content
;; to some formats
(define-record-type <page>
(make-page file-name contents writer)
is-page?
Expand Down Expand Up @@ -49,11 +52,12 @@
(define* (page post prefix-directory
#:optional (process-layer default-process-layer)
#:key (writer (create-writer)))
(let ((file-name (get-post-file-name post)))
(let ((file-name (regexp-substitute #f (string-match ".[a-zA-Z]+$" (get-post-file-name post)) ;; use regexp to change the ext to "html"
'pre ".html")))
(let ((page* (make-page file-name
((get-processor (assq-ref process-layer 'meta))
#:process-layer process-layer
;; the process-object is an post-object
;; the process-object is a post-object
#:process-object post)
writer)))
(write-page page* prefix-directory))))
57 changes: 52 additions & 5 deletions Flax/post.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
set-post-sxml

read-post
post-ref))
post-ref
register-metadata-parser!
read-metadata-headers
parse-metadata))


;; ~metadata~ is an alist
Expand All @@ -30,10 +33,54 @@
(metadata get-post-metadata)
(sxml get-post-sxml set-post-sxml))

;; read one post and return post object
(define (read-post file-name)
(let-values (((meta-data content) ((get-reader-proc sxml-reader) file-name)))
(make-post (basename file-name) meta-data content)))
;; read one post and return post object
(define* (read-post file-name #:key (reader-list default-reader-list))
(if (pair? reader-list)
(if (is-reader-available? (car reader-list) file-name)
(let-values (((meta-data content) (proc-of-reader (car reader-list) file-name)))
(make-post (basename file-name) meta-data content))
(read-post file-name #:reader-list (cdr reader-list)))
(begin
(format (current-error-port) "Unmatched file : ~a ~%" file-name)
'())))

(define (post-ref post key)
(assq-ref (get-post-metadata post) key))


;; read meta data
(define %metadata-parsers
(make-hash-table))

(define (register-metadata-parser! name parser)
(hash-set! %metadata-parsers name parser))

(define (metadata-parser key)
(or (hash-ref %metadata-parsers key) identity))

(define (parse-metadata key value)
((metadata-parser key) value))

(define (read-metadata-headers port)
(let loop ((metadata '()))
(let ((line (read-line port)))
(cond
((eof-object? line)
(error "end of file while readig metadata: " (port-filename port)))
((string=? line "---")
metadata)
(else
(match (map string-trim-both (string-split-at line #\:))
(((= string->symbol key) value)
(loop (alist-cons key (parse-metadata key value) metadata)))
(_ error "invalid metadata format: " line)))))))

(register-metadata-parser!
'type
(lambda (str)
(string->symbol str)))

(register-metadata-parser!
'depth
(lambda (str)
(string->number str)))
31 changes: 29 additions & 2 deletions Flax/process.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,41 @@
get-processor
set-processor

default-process-layer))
default-process-layer
process-ref
processor-ref))


;; defien the record of <process>
(define-record-type <process>
(make-process key processor)
is-process?
(key get-process-key set-process-key) ;; you'd better set the key as symbol
(processor get-processor set-processor)) ;; the processor is a procedure which process the sxml tree


;; return the process from the process-layer otherwise
;; return '()
(define (process-ref process-layer key)
(assq-ref process-layer key))

;; return the processor of one process in process-layer
(define (processor-ref process-layer key)
(get-processor (process-ref process-layer key)))


;; read each post, genereate an alist of post path , not completed!!!!!!!!!!!!!!
(define (Hello)
(format #t "This is not done!!~%"))

;; ---------------------------the default process layer------------------------------------------------
;; this template require these keywords in post
;; img -- the preview image path, from the index file to that image, pure String
;; title -- the title of the post, pure String
;; author -- Your name, pure String
;; date -- the date the post posted, Pure String
;; tag -- The type of the post, Pure String
;; this will show later in the end of the file
(define default-meta-process
(make-process 'meta
(lambda* (#:key process-layer process-object)
Expand Down Expand Up @@ -64,7 +91,7 @@
;; date if none output "today" -- date is a string
;; img if none don't display the image -- img is a src string
;; tag if none output "none" -- tag is a !!string list!!
;; content -- must have! otherwise you will get one post with out content
;; content -- must have! otherwise you will get one post without content
(define default-process-layer
`((meta . ,default-meta-process)
(index . ,default-index-process)
Expand Down
36 changes: 36 additions & 0 deletions Flax/process/utils.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(define-module (Flax process utils)
#:use-module (Flax post)
#:use-module (Flax utils)

#:use-module (ice-9 regex)
#:use-module (ice-9 match)

#:export (navigate))


;; navigate between files, read the post, use action to process each
;; post, and then return a list, this action is defined by user and the
;; action is a function which accept a post . you can do what you want.
;; Don't use the flag keyword in any situation!
;; You can set the environment keyword if you need to.
(define* (navigate file-tree action #:key (flag #f) (environment (getcwd)))
(if (not (pair? file-tree))
'()
(let ((environment* (if flag
(string-append environment "/" (car file-tree))
environment))
(file-tree* (if flag
(cdr file-tree)
file-tree)))
(append (if (pair? (car file-tree*))
(navigate (car file-tree*)
action
#:flag #t
#:environment environment*)
(action (if (not (is-directory? (string-append environment* "/" (car file-tree*))))
(read-post (string-append environment* "/" (car file-tree*)))
'())))
(navigate (cdr file-tree*)
action
#:flag #f
#:environment environment*)))))
28 changes: 25 additions & 3 deletions Flax/reader.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

(define-module (Flax reader)
#:use-module (Flax utils)
#:use-module (Flax post)

#:use-module (srfi srfi-1) ;;alist-delete procedure
#:use-module (srfi srfi-9)
Expand All @@ -10,16 +10,21 @@
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
#:use-module (sxml simple)

#:use-module (commonmark)

#:export (make-reader
is-reader?
get-reader-matcher
set-reader-matcher-as
get-reader-proc
is-reader-available?

proc-of-reader

sxml-reader
commonmark-reader
make-file-extension-matcher
sxml-reader))
default-reader-list))


;; ~matcher~ is a function to judge whether the file is supported
Expand All @@ -31,6 +36,7 @@
(matcher get-reader-matcher set-reader-matcher-as)
(proc get-reader-proc))

;; make file extension matcher
;; return the function which returns #t if the file is
;; end with ".~ext~"
(define (make-file-extension-matcher ext)
Expand All @@ -40,13 +46,19 @@
(regexp-match? (regexp-exec regexp file-name)))))



;; return #t if the ~file-name~ is supported by ~reader~
(define (is-reader-available? reader file-name)
((get-reader-matcher reader) file-name))

;; use reader's process to do things
(define (proc-of-reader reader file-name)
((get-reader-proc reader) file-name))

;;;;;;;;;;; ;;;;;;;;;;;
;;;; define simple reader ;;;
;;;;;;;;;;; ;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; sxml-reader
;; take the file as the scheme code and then read it
(define sxml-reader
Expand All @@ -55,3 +67,13 @@
(let ((contents (load (get-absolute-path file-name))))
(values (alist-delete 'content contents eq?) ;; return the metadata list
(assq-ref contents 'content)))))) ;; return the list

(define commonmark-reader
(make-reader (make-file-extension-matcher "md")
(lambda (file-name)
(call-with-input-file file-name
(lambda (port)
(values (read-metadata-headers port)
(commonmark->sxml port)))))))

(define default-reader-list (list sxml-reader commonmark-reader))
7 changes: 1 addition & 6 deletions Flax/script/flax.scm
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#!/usr/bin/guile
#!/usr/bin/guile --no-auto-compile
-*- scheme -*-
!#

;; command option
;; --no-auto-compile


;; NOTE: for test
(add-to-load-path
"/home/eilliot/Lasga/Repository/Local_Repository/Guile/Dev")

;;Add modules here
(use-modules (Flax ui))

Expand Down
Loading

0 comments on commit eda3c17

Please sign in to comment.