diff options
author | Volpeon <git@volpeon.ink> | 2020-12-28 21:34:30 +0100 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2020-12-28 21:34:30 +0100 |
commit | 5ab5e6a4781c53aade17a9a98e123762691205c6 (patch) | |
tree | c8a1eed27676e2118a8a44270a9ffa82e9e98b13 | |
parent | Export pages grouped by year as array instead of object (diff) | |
download | volpeon.ink-5ab5e6a4781c53aade17a9a98e123762691205c6.tar.gz volpeon.ink-5ab5e6a4781c53aade17a9a98e123762691205c6.tar.bz2 volpeon.ink-5ab5e6a4781c53aade17a9a98e123762691205c6.zip |
Handle blog entry categories
-rw-r--r-- | assets/css/_basics.scss | 2 | ||||
-rw-r--r-- | assets/css/components/_hlist.scss | 13 | ||||
-rw-r--r-- | assets/css/components/_spacer.scss | 5 | ||||
-rw-r--r-- | assets/css/style.scss | 2 | ||||
-rw-r--r-- | content/blog/test1.md | 1 | ||||
-rw-r--r-- | content/blog/test2/index.md | 1 | ||||
-rw-r--r-- | content/projects/index.md | 5 | ||||
-rw-r--r-- | metadata/categories.json | 4 | ||||
-rw-r--r-- | metadata/metadata.yaml | 3 | ||||
-rwxr-xr-x | scripts/build_content.sh | 52 | ||||
-rw-r--r-- | scripts/metadata_tpl.json | 3 | ||||
-rw-r--r-- | templates/base.html | 1 | ||||
-rw-r--r-- | templates/categoryRef.html | 7 | ||||
-rw-r--r-- | templates/pagelistByYear.html | 4 |
14 files changed, 76 insertions, 27 deletions
diff --git a/assets/css/_basics.scss b/assets/css/_basics.scss index a8ed013..2b0d0a6 100644 --- a/assets/css/_basics.scss +++ b/assets/css/_basics.scss | |||
@@ -144,7 +144,7 @@ p { | |||
144 | 144 | ||
145 | hr { | 145 | hr { |
146 | height: 1px; | 146 | height: 1px; |
147 | margin: ($line-height * 2em) 0 ($line-height * 2em); | 147 | margin: ($line-height * 2em) 0; |
148 | border: 0; | 148 | border: 0; |
149 | background-color: var(--obj); | 149 | background-color: var(--obj); |
150 | } | 150 | } |
diff --git a/assets/css/components/_hlist.scss b/assets/css/components/_hlist.scss new file mode 100644 index 0000000..a7cf665 --- /dev/null +++ b/assets/css/components/_hlist.scss | |||
@@ -0,0 +1,13 @@ | |||
1 | .c-hlist { | ||
2 | display: flex; | ||
3 | |||
4 | &__item { | ||
5 | display: block; | ||
6 | margin-right: 4ch; | ||
7 | padding-left: 0; | ||
8 | |||
9 | &::before { | ||
10 | display: none; | ||
11 | } | ||
12 | } | ||
13 | } | ||
diff --git a/assets/css/components/_spacer.scss b/assets/css/components/_spacer.scss new file mode 100644 index 0000000..692eb29 --- /dev/null +++ b/assets/css/components/_spacer.scss | |||
@@ -0,0 +1,5 @@ | |||
1 | .c-spacer { | ||
2 | display: block; | ||
3 | height: 0; | ||
4 | margin: ($line-height * 2em) 0 0; | ||
5 | } | ||
diff --git a/assets/css/style.scss b/assets/css/style.scss index 8d9a87f..90c1bfc 100644 --- a/assets/css/style.scss +++ b/assets/css/style.scss | |||
@@ -2,6 +2,8 @@ | |||
2 | @import 'functions'; | 2 | @import 'functions'; |
3 | @import 'basics'; | 3 | @import 'basics'; |
4 | 4 | ||
5 | @import 'components/spacer'; | ||
6 | @import 'components/hlist'; | ||
5 | @import 'components/nav'; | 7 | @import 'components/nav'; |
6 | @import 'components/page-header'; | 8 | @import 'components/page-header'; |
7 | 9 | ||
diff --git a/content/blog/test1.md b/content/blog/test1.md index 8e2b0b9..05c2b2d 100644 --- a/content/blog/test1.md +++ b/content/blog/test1.md | |||
@@ -1,6 +1,7 @@ | |||
1 | --- | 1 | --- |
2 | date: 2020-12-25 | 2 | date: 2020-12-25 |
3 | title: Test Page 1 | 3 | title: Test Page 1 |
4 | category: tes | ||
4 | --- | 5 | --- |
5 | 6 | ||
6 | # Test Page 1 | 7 | # Test Page 1 |
diff --git a/content/blog/test2/index.md b/content/blog/test2/index.md index 70130d1..9d1ebd2 100644 --- a/content/blog/test2/index.md +++ b/content/blog/test2/index.md | |||
@@ -1,6 +1,7 @@ | |||
1 | --- | 1 | --- |
2 | date: 2020-12-21 | 2 | date: 2020-12-21 |
3 | title: Test Page 2 | 3 | title: Test Page 2 |
4 | category: per | ||
4 | --- | 5 | --- |
5 | 6 | ||
6 | # Test Page 2 | 7 | # Test Page 2 |
diff --git a/content/projects/index.md b/content/projects/index.md deleted file mode 100644 index fd5a713..0000000 --- a/content/projects/index.md +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | --- | ||
2 | title: Projects | ||
3 | --- | ||
4 | |||
5 | # Projects | ||
diff --git a/metadata/categories.json b/metadata/categories.json new file mode 100644 index 0000000..b0c5f84 --- /dev/null +++ b/metadata/categories.json | |||
@@ -0,0 +1,4 @@ | |||
1 | { | ||
2 | "tes": "Testing", | ||
3 | "per": "Personal" | ||
4 | } | ||
diff --git a/metadata/metadata.yaml b/metadata/metadata.yaml index eb0f054..d2d4b1f 100644 --- a/metadata/metadata.yaml +++ b/metadata/metadata.yaml | |||
@@ -10,6 +10,3 @@ menus: | |||
10 | - id: blog | 10 | - id: blog |
11 | label: Blog | 11 | label: Blog |
12 | url: /blog/ | 12 | url: /blog/ |
13 | - id: projects | ||
14 | label: Projects | ||
15 | url: /projects/ | ||
diff --git a/scripts/build_content.sh b/scripts/build_content.sh index cf0128b..719b7c9 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh | |||
@@ -1,9 +1,13 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | CONTENT_DIR="content/" | 3 | CONTENT_DIR="content/" |
4 | METADATA_DIR="metadata/" | ||
4 | TEMPLATES_DIR="templates/" | 5 | TEMPLATES_DIR="templates/" |
5 | OUTPUT_DIR="output/" | 6 | OUTPUT_DIR="output/" |
6 | 7 | ||
8 | CATEGORY_SHORT_LEN=3 | ||
9 | CATEGORY_MAP=$(cat "$METADATA_DIR/categories.json") | ||
10 | |||
7 | target_filename () { | 11 | target_filename () { |
8 | filename=$1 | 12 | filename=$1 |
9 | filename=${filename#"$CONTENT_DIR"} | 13 | filename=${filename#"$CONTENT_DIR"} |
@@ -44,7 +48,7 @@ get_subpages_basedir() { | |||
44 | echo "$filename" | 48 | echo "$filename" |
45 | } | 49 | } |
46 | 50 | ||
47 | get_subpages() { | 51 | get_metadata() { |
48 | basedir=$(get_subpages_basedir "$1") | 52 | basedir=$(get_subpages_basedir "$1") |
49 | child_pages=() | 53 | child_pages=() |
50 | 54 | ||
@@ -68,10 +72,12 @@ get_subpages() { | |||
68 | if [ ${#child_pages[@]} -ne 0 ]; then | 72 | if [ ${#child_pages[@]} -ne 0 ]; then |
69 | #echo -e "\033[0;90m[////////]\033[0m Child pages:" | 73 | #echo -e "\033[0;90m[////////]\033[0m Child pages:" |
70 | 74 | ||
71 | collected_metadata=$(echo "{ | 75 | pages=$(echo "{}" | jq ". + { \ |
72 | \"all\": [], | 76 | all: [], \ |
73 | \"by_year\": {} | 77 | by_year: {} \ |
74 | }" | jq .) | 78 | }") |
79 | |||
80 | categories="{}" | ||
75 | 81 | ||
76 | for file in "${child_pages[@]}"; do | 82 | for file in "${child_pages[@]}"; do |
77 | #echo -e "\033[0;90m[////////]\033[0m - $file" | 83 | #echo -e "\033[0;90m[////////]\033[0m - $file" |
@@ -84,27 +90,41 @@ get_subpages() { | |||
84 | -t plain \ | 90 | -t plain \ |
85 | --template scripts/metadata_tpl.json) | 91 | --template scripts/metadata_tpl.json) |
86 | 92 | ||
87 | metadata=$(echo "$metadata" | jq ". + { url_rel: \"$url_rel\", url_abs: \"$url_abs\" }") | 93 | date=$(echo "$metadata" | jq -r .date) |
94 | category=$(echo "$metadata" | jq -r .category) | ||
95 | category_name=$(echo "$CATEGORY_MAP" | jq -r .$category) | ||
88 | 96 | ||
89 | collected_metadata=$(echo "$collected_metadata" | jq ".all += [ $metadata ]") | 97 | metadata=$(echo "$metadata" | jq ". + { \ |
98 | url_rel: \"$url_rel\", \ | ||
99 | url_abs: \"$url_abs\" \ | ||
100 | }") | ||
90 | 101 | ||
91 | date=$(echo "$metadata" | jq -r .date) | 102 | pages=$(echo "$pages" | jq ".all += [ $metadata ]") |
103 | |||
104 | if [ "$category" != "" ]; then | ||
105 | categories=$(echo "$categories" | jq ". + { $category: \"$category_name\" }") | ||
106 | fi | ||
92 | 107 | ||
93 | if [ "$date" != "" ]; then | 108 | if [ "$date" != "" ]; then |
94 | date_year=$(date -d "$date" +%Y) | 109 | date_year=$(date -d "$date" +%Y) |
95 | #date_month=$(date -d "$date" +%m) | 110 | #date_month=$(date -d "$date" +%m) |
96 | #date_day=$(date -d "$date" +%d) | 111 | #date_day=$(date -d "$date" +%d) |
97 | 112 | ||
98 | collected_metadata=$(echo "$collected_metadata" | jq ".by_year.\"$date_year\" += [ $metadata ]") | 113 | pages=$(echo "$pages" | jq ".by_year.\"$date_year\" += [ $metadata ]") |
99 | fi | 114 | fi |
100 | done | 115 | done |
101 | 116 | ||
102 | collected_metadata=$(echo "$collected_metadata" \ | 117 | pages=$(echo "$pages" \ |
103 | | jq ".all |= (sort_by(.date) | reverse)" \ | 118 | | jq ".all |= (sort_by(.date) | reverse) \ |
104 | | jq ".by_year[] |= (sort_by(.date) | reverse)" \ | 119 | | .by_year |= (to_entries | sort_by(.key) | reverse \ |
105 | | jq ".by_year |= (to_entries | sort_by(.key) | reverse)") | 120 | | .[].value |= (sort_by(.date) | reverse))") |
121 | |||
122 | categories=$(echo "$categories" | jq ". | to_entries | sort_by(.key)") | ||
106 | 123 | ||
107 | echo "{ \"pages\": $collected_metadata }" | jq . | 124 | echo "{}" | jq ". + { \ |
125 | pages: $pages, \ | ||
126 | categories: $categories \ | ||
127 | }" | ||
108 | fi | 128 | fi |
109 | } | 129 | } |
110 | 130 | ||
@@ -125,8 +145,8 @@ handle () { | |||
125 | 145 | ||
126 | subpages_meta_file=$(mktemp) | 146 | subpages_meta_file=$(mktemp) |
127 | 147 | ||
128 | # echo "$(get_subpages "$1")" | 148 | # echo "$(get_metadata "$1")" |
129 | echo "$(get_subpages "$1")" > "$subpages_meta_file" | 149 | echo "$(get_metadata "$1")" > "$subpages_meta_file" |
130 | 150 | ||
131 | pandoc "$1" \ | 151 | pandoc "$1" \ |
132 | -f markdown \ | 152 | -f markdown \ |
diff --git a/scripts/metadata_tpl.json b/scripts/metadata_tpl.json index eeda341..76e4439 100644 --- a/scripts/metadata_tpl.json +++ b/scripts/metadata_tpl.json | |||
@@ -1,4 +1,5 @@ | |||
1 | { | 1 | { |
2 | "title": "$title$", | 2 | "title": "$title$", |
3 | "date": "$date$" | 3 | "date": "$date$", |
4 | "category": "$category$" | ||
4 | } | 5 | } |
diff --git a/templates/base.html b/templates/base.html index 8d10d13..330e759 100644 --- a/templates/base.html +++ b/templates/base.html | |||
@@ -49,6 +49,7 @@ ${pageHeader()} | |||
49 | $body$ | 49 | $body$ |
50 | 50 | ||
51 | $if(isblog)$ | 51 | $if(isblog)$ |
52 | ${categoryRef()} | ||
52 | ${pagelistByYear()} | 53 | ${pagelistByYear()} |
53 | $endif$ | 54 | $endif$ |
54 | </div> | 55 | </div> |
diff --git a/templates/categoryRef.html b/templates/categoryRef.html new file mode 100644 index 0000000..9a363cf --- /dev/null +++ b/templates/categoryRef.html | |||
@@ -0,0 +1,7 @@ | |||
1 | $if(categories)$ | ||
2 | <ul class="c-hlist"> | ||
3 | $for(categories)$ | ||
4 | <li class="c-hlist__item"><strong>$it.key/uppercase$</strong>: $it.value$</li> | ||
5 | $endfor$ | ||
6 | </ul> | ||
7 | $endif$ | ||
diff --git a/templates/pagelistByYear.html b/templates/pagelistByYear.html index 972bacc..20ce6c4 100644 --- a/templates/pagelistByYear.html +++ b/templates/pagelistByYear.html | |||
@@ -1,9 +1,11 @@ | |||
1 | $for(pages)$ | 1 | $for(pages)$ |
2 | $for(it.by_year)$ | 2 | $for(it.by_year)$ |
3 | $-- <hr class="c-spacer" /> | ||
4 | $-- <h2>$it.key$</h2> | ||
3 | <ul class="s-refs"> | 5 | <ul class="s-refs"> |
4 | $for(it.value)$ | 6 | $for(it.value)$ |
5 | <li> | 7 | <li> |
6 | <a href="$it.url_rel$">$it.date$ - $it.title$</a> | 8 | <a href="$it.url_rel$">$it.category/uppercase$ $it.date$ - $it.title$</a> |
7 | </li> | 9 | </li> |
8 | $endfor$ | 10 | $endfor$ |
9 | </ul> | 11 | </ul> |