code for blog/thoughts
This commit is contained in:
77
www/src/pages/html/view-thought.hy
Normal file
77
www/src/pages/html/view-thought.hy
Normal file
@ -0,0 +1,77 @@
|
||||
(do ;; required for arcane scoping
|
||||
(defn check-param-exists [param-name]
|
||||
#[f[test "$(echo '{{' '{param-name}' '}}' | sed 's/ //g')" != '{{{param-name}}}']f])
|
||||
|
||||
(defn if-param-then-else [param-name param-defined otherwise [echo True]]
|
||||
#[f[ {(check-param-exists param-name)} && {(if echo "echo " "")}{param-defined} || {(if echo "echo " "")}{otherwise} ]f])
|
||||
|
||||
(defn param-if-param-else [param-name otherwise]
|
||||
(if-param-then-else param-name f"'{{{param-name}}}'" otherwise))
|
||||
|
||||
(defn get-thought-param-field [field]
|
||||
#[f[ cat www/data/thought-registry | grep -P "\t{{thought}}\t" | awk -v FS=$'\t' '{{print ${(get (dict :tags "1" :file-name "2" :title "3" :date "4" :description "5") field)}}}' ]f])
|
||||
|
||||
(defn subshell [#* lines]
|
||||
#[f[({(.join "; " lines)})]f])
|
||||
|
||||
(setv thought-tag-format (form->html
|
||||
`(a (:href "?filter-tag=${tag}") "${tag}")))
|
||||
|
||||
(setv thought-tag-list-format
|
||||
#[f[tags: $(while read -r tag{";"} do echo "{thought-tag-format}"{";"} done <<< "${{tags//{#[[;]]}/$'\n'}}")]f])
|
||||
|
||||
(setv thought-list-entry-format (form->html
|
||||
`(div (:id "${file_name}" :class thought-list-entry)
|
||||
(div (:class title) (a (:href "\\?thought=${file_name}") "${title}"))
|
||||
(div (:class date) "${date}")
|
||||
(div (:class description) "${description}")
|
||||
(div (:class categories) ~#[f[$(echo {thought-tag-list-format})]f]))))
|
||||
|
||||
(setv thought-display-meta-format (form->html
|
||||
`(div (:class thought-meta)
|
||||
(div (:class date) "${date}")
|
||||
(div (:class tags) ~#[f[$(echo "{thought-tag-list-format}")]f]))))
|
||||
|
||||
(defn thought [[title "empty title"] [description ""] [date "1970-01-01"] [tags []] [content '(p "no content provided")]]
|
||||
(inherit page-name)
|
||||
(with [thought-registry (open "../data/thought-registry" "a")]
|
||||
(.write thought-registry f"{(.join #[[;]] tags)}\t{(get page-name -1)}\t{title}\t{date}\t{description}\n"))
|
||||
|
||||
`(
|
||||
~content
|
||||
~(run "put-footnotes")
|
||||
~(comments f"/html/thought/view-thought.html?thought={(get page-name -1)}")))
|
||||
|
||||
(run "echo -n > ../data/thought-registry")
|
||||
|
||||
(page
|
||||
:title #[f[$[{(param-if-param-else "thought" "natalie thoughts")}]]f]
|
||||
:description #[f[
|
||||
$[{(if-param-then-else "thought" #[f["$({(get-thought-param-field "description")})"]f] #[f[
|
||||
$({(if-param-then-else
|
||||
"filter-tag"
|
||||
"'thoughts filtered for "{filter-tag}"'"
|
||||
"an enumeration of natalie thoughts. it is functionally a blog")})]f])}]]f]
|
||||
|
||||
`(section
|
||||
(h1 ~#[f[
|
||||
$[{(if-param-then-else "thought" #[f[$({(get-thought-param-field "title")})]f] #[f[
|
||||
$({(if-param-then-else
|
||||
"filter-tag"
|
||||
"'thoughts filtered for "{filter-tag}"'"
|
||||
"natalie thoughts. functionally a blog")})]f])}]]f])
|
||||
|
||||
(div (:class ~#[f[$[{(if-param-then-else "thought" "thought" "thought-list")}]]f])
|
||||
~#[f[$[{(if-param-then-else
|
||||
"thought"
|
||||
#[f[{(subshell
|
||||
#[f[tags=$({(get-thought-param-field "tags")})]f]
|
||||
#[f[date=$({(get-thought-param-field "date")})]f]
|
||||
#[f[echo "{thought-display-meta-format}"]f]
|
||||
#[f[include ./www/site/html/html/thoughts/$({(get-thought-param-field "file_name")}).html]f])}]f]
|
||||
#[f[cat www/data/thought-registry | eval $({(if-param-then-else
|
||||
"filter-tag"
|
||||
#[-[grep '{filter-tag}']-]
|
||||
#[-["grep -E '.*'"]-])}) | sort -t$'\t' -k4 -nr | while IFS=$'\t' read -r tags file_name title date description{";"} do echo "{thought-list-entry-format}"{";"} done]f]
|
||||
:echo False)}]]f]))))
|
||||
|
Reference in New Issue
Block a user