@@ -97,15 +97,10 @@ (define table_articles (make-table-schema "articles" table_articles-fields)) (define table_notes (make-table-schema "notes" table_notes-fields #:primary-key-cols '(pagenode note_id))) (define table_series (make-table-schema "series" table_series-fields)) -;; Split all ◊note tags out of the Pollen doc -(define (doc->body/notes doc) - (define (is-note? tx) (and (txexpr? tx) (equal? 'note (get-tag tx)))) - (splitf-txexpr doc is-note?)) - ;; ~~~ Provided functions: Initializing; Saving posts and notes ;; Initialize the database connection, creating the database if it doesn’t ;; exist, and executing the table schema queries ;; @@ -114,74 +109,71 @@ ;; Save an article and its notes (if any) to the database, and return the ;; rendered HTML of the complete article. ;; (define (crystalize-article! pagenode doc) - (define pubdate (select-from-metas 'published (current-metas))) - (define-values (body-txpr note-txprs) (doc->body/notes doc)) - (define doc-html (->html (cdr body-txpr))) - + (define-values + (doc2 maybe-title) (splitf-txexpr doc (make-tag-predicate 'title))) + (define-values + (body-txpr note-txprs) (splitf-txexpr doc2 (make-tag-predicate 'note))) (define-values (disposition disp-note-id) (notes->last-disposition-values note-txprs)) - (define title-specified? (non-empty-string? (maybe-meta 'title))) - (define-values (title-plain title-html-flow) - (title-plain+html-values body-txpr disposition)) - (define series-node (maybe-meta 'series)) - (define header (html$-article-open title-specified? title-html-flow pubdate)) - - (define footertext (make-article-footertext pagenode series-node disposition disp-note-id (length note-txprs))) - (define footer (html$-article-close footertext)) - - (define notes-section-html (crystalize-notes! pagenode title-plain note-txprs)) - - ;; Values must come in the order defined in table_article_fields - (define article-record - (list (symbol->string pagenode) - title-plain - title-html-flow - (bool->int title-specified?) - pubdate - (maybe-meta 'updated) - (maybe-meta 'author default-authorname) - (maybe-meta 'conceal) - series-node - (maybe-meta 'noun (series-noun)) - (length note-txprs) - doc-html - disposition - disp-note-id - (string-append header doc-html footer) - "" ; listing_excerpt_html: Not yet used - "")) ; listing_short_html: Not yet used - - (apply query! (make-insert/replace-query 'articles table_articles-fields) article-record) - - (string-append header doc-html notes-section-html footer)) + + (let* ([pubdate (select-from-metas 'published (current-metas))] + [doc-html (->html (cdr body-txpr))] + [title-specified? (not (equal? '() maybe-title))] + [title-val (if (not (null? maybe-title)) (car maybe-title) maybe-title)] + [title-tx (make-article-title title-val body-txpr disposition disp-note-id)] + [title-html (->html title-tx)] + [title-plain (tx-strs title-tx)] + [series-node (series-pagenode)] + [header (html$-article-open title-specified? title-tx pubdate)] + [footertext (make-article-footertext pagenode series-node disposition disp-note-id (length note-txprs))] + [footer (html$-article-close footertext)] + [notes-section-html (crystalize-notes! pagenode title-plain note-txprs)]) + + ;; Values must come in the order defined in table_article_fields + (define article-record + (list (symbol->string pagenode) + title-plain + title-html + (bool->int title-specified?) + pubdate + (maybe-meta 'updated) + (maybe-meta 'author default-authorname) + (maybe-meta 'conceal) + (symbol->string series-node) + (maybe-meta 'noun (series-noun)) + (length note-txprs) + doc-html + disposition + disp-note-id + (string-append header doc-html footer) + "" ; listing_excerpt_html: Not yet used + "")) ; listing_short_html: Not yet used + + (apply query! (make-insert/replace-query 'articles table_articles-fields) article-record) + + (string-append header doc-html notes-section-html footer))) ;; ~~~ Article-related helper functions ~~~ ;; -;; Return both a plain-text and HTML version of a title for the current article, -;; supplying a default if no title was specified in the metas. -(define (title-plain+html-values body-tx disposition) - (define title (maybe-meta 'title "")) - (define title-val - (cond [(and (string? title) (string=? title "")) - (format "“~a…”" (first-words (tx-strs body-tx) 5))] - [else title])) +;; Return a title txexpr for the current article, constructing a default if no title text was specified. +(define (make-article-title supplied-title body-tx disposition disp-note-id) + (define title-elems + (cond [(null? supplied-title) (list (default-title (get-elements body-tx)))] + [else (get-elements supplied-title)])) (define disposition-part (cond [(non-empty-string? disposition) (define-values (mark _) (disposition-values disposition)) - (format "~a" mark)] + `(span [[class "disposition-mark"]] (a [[href ,(string-append "#" disp-note-id)]] ,mark))] [else ""])) + ;; Returns a txexpr, the tag will be discarded by the template/snippets + `(title ,@title-elems ,disposition-part)) - (cond [(txexpr? title-val) - (values (apply string-append (tx-strs title-val)) - (string-append (->html title-val) disposition-part))] - [else (values title-val (string-append title-val disposition-part))])) - ;; Convert a bunch of information about an article into some nice English and links. (define (make-article-footertext pagenode series disposition disp-note-id note-count) (define s-title (series-title)) (define s-noun (series-noun)) (define series-part