diff options
| author | Paul Buetow <paul@buetow.org> | 2022-11-23 20:45:21 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2022-11-23 20:45:21 +0200 |
| commit | 5bbae36a59881e34fe111c0ee9f44f3907158301 (patch) | |
| tree | 85d2b8da1f33c327f57def0ba31a178872050a3d /lib | |
| parent | 6682bd7c4c45283acdb161765dac58ec034899bd (diff) | |
| parent | 4c4f379ea616eeec320ec27776c739fadf70d2da (diff) | |
merge
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/atomfeed.source.sh | 52 | ||||
| -rw-r--r-- | lib/gemfeed.source.sh | 9 | ||||
| -rw-r--r-- | lib/generate.source.sh | 22 | ||||
| -rw-r--r-- | lib/html.source.sh | 3 | ||||
| -rw-r--r-- | lib/notes.source.sh | 5 |
5 files changed, 80 insertions, 11 deletions
diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh index 716ef5c..65afa5a 100644 --- a/lib/atomfeed.source.sh +++ b/lib/atomfeed.source.sh @@ -32,27 +32,65 @@ META cat "$meta_file" } -# Retrieve the core content as XHTML of the blog post. -atomfeed::content () { +atomfeed::_from_cache () { local -r gmi_file_path="$1"; shift - log VERBOSE "Retrieving feed content from $gmi_file_path" + local -r cache_file_path="$1"; shift + + if [ ! -f "${cache_file_path}.info" ]; then + # No cache there. + return 1 + elif ! diff "${cache_file_path}.info" <(ls -l "$gmi_file_path"); then + # Need to refresh the cache. + return 1 + fi + + log VERBOSE "Retrieving feed content for $gmi_file_path from $cache_file_path" + cat "$cache_file_path" +} + +atomfeed::_make_cache () { + local -r gmi_file_path="$1"; shift + local -r cache_file_path="$1"; shift + + log VERBOSE "Making feed content cache from $gmi_file_path" + + local -r cache_file_dir="$(dirname "$cache_file_path")" + if [ ! -d "$cache_file_dir" ]; then + mkdir -p "$cache_file_dir" + fi # sed: Remove all before the first header # sed: Make HTML links absolute, Atom relative URLs feature seems a mess # across different Atom clients. html::fromgmi < <($SED '/Go back to the main site/d' "$gmi_file_path") | - $SED " - s|href=\"\./|href=\"https://$DOMAIN/gemfeed/|g; - s|src=\"\./|src=\"https://$DOMAIN/gemfeed/|g; - " + $SED "s|href=\"\./|href=\"https://$DOMAIN/gemfeed/|g; + s|src=\"\./|src=\"https://$DOMAIN/gemfeed/|g;" | + tee "$cache_file_path" + + ls -l "$gmi_file_path" > "${cache_file_path}.info" +} + +# Retrieve the core content as XHTML of the blog post. +atomfeed::content () { + local -r gmi_file_path="$1"; shift + local -r cache_file_path="${gmi_file_path/gemtext/cache}.atomcache" + + atomfeed::_from_cache "$gmi_file_path" "$cache_file_path" || + atomfeed::_make_cache "$gmi_file_path" "$cache_file_path" } # Generate an atom.xml feed file. atomfeed::generate () { local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" + if [ ! -d "$gemfeed_dir" ]; then + return + fi + local -r atom_file="$gemfeed_dir/atom.xml" local -r now=$($DATE --iso-8601=seconds) + log INFO "Generating Atom feed to $atom_file" + log INFO 'This may takes a while with an empty cache....' assert::not_empty now "$now" diff --git a/lib/gemfeed.source.sh b/lib/gemfeed.source.sh index 1b2ee5c..6cb9a5a 100644 --- a/lib/gemfeed.source.sh +++ b/lib/gemfeed.source.sh @@ -3,9 +3,7 @@ gemfeed::get_posts () { local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" local -r gmi_pattern='^[0-9]{4}-[0-9]{2}-[0-9]{2}-.*\.gmi$' - ls "$gemfeed_dir" | - $GREP -E "$gmi_pattern" | - sort -r + ls "$gemfeed_dir" | $GREP -f -v DRAFT- | $GREP -E "$gmi_pattern" | sort -r } # Add the links from gemfeed/index.gmi to the main index site. @@ -32,6 +30,11 @@ gemfeed::_get_word_count () { # Generate a index.gmi in the ./gemfeed subdir. gemfeed::generate () { local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" + if [ ! -d "$gemfeed_dir" ]; then + log INFO "Capsule without Gemfeed" + return + fi + log INFO "Generating Gemfeed index for $gemfeed_dir" cat <<GEMFEED > "$gemfeed_dir/index.gmi.tmp" diff --git a/lib/generate.source.sh b/lib/generate.source.sh index b2dafbc..9a9e90b 100644 --- a/lib/generate.source.sh +++ b/lib/generate.source.sh @@ -63,6 +63,10 @@ generate::convert_gmi_atom_to_html_atom () { return fi + if [ ! -f "$CONTENT_BASE_DIR/gemtext/gemfeed/atom.xml" ]; then + return + fi + log INFO 'Converting Gemtext Atom feed to HTML Atom feed' $SED 's|.gmi|.html|g; s|gemini://|https://|g' \ @@ -124,6 +128,11 @@ generate::fromgmi () { # Add content while read -r src; do + # User can specify a content filter + if test ! -z "$CONTENT_FILTER" && ! $GREP -q "$CONTENT_FILTER" <<< "$src"; then + continue + fi + num_gmi_files=$(( num_gmi_files + 1 )) log INFO "Generating output formats from $src" for format in "$@"; do @@ -176,3 +185,16 @@ generate::fromgmi () { done log INFO "You may want to commit all changes to version control!" } + +# Only generate draft posts +generate::draft () { + if [ ! -z "$CONTENT_FILTER" ]; then + log ERROR "ERROR, you can't set a content filter manually in draft mode" + exit 2 + fi + CONTENT_FILTER=DRAFT- + generate::fromgmi $@ + + log INFO 'For HTML preview, open in your browser:' + find $CONTENT_BASE_DIR/html -name DRAFT-\*.html +} diff --git a/lib/html.source.sh b/lib/html.source.sh index c303d2e..03bbb45 100644 --- a/lib/html.source.sh +++ b/lib/html.source.sh @@ -98,7 +98,8 @@ html::fromgmi () { while IFS='' read -r line; do if [[ "$is_list" == yes ]]; then if [[ "$line" == '* '* ]]; then - echo "<li>$(html::encode "${line/\* /}")</li>" + echo "<li>$(html::encode "${line/\* /}")</li>" | + html::process_inline else is_list=no echo "</ul>" diff --git a/lib/notes.source.sh b/lib/notes.source.sh index b82631d..0f5251d 100644 --- a/lib/notes.source.sh +++ b/lib/notes.source.sh @@ -11,6 +11,11 @@ notes::_get_notes () { # Generate a index.gmi in the ./notes subdir. notes::generate () { local -r notes_dir="$CONTENT_BASE_DIR/gemtext/notes" + if [ ! -d "$notes_dir" ]; then + log INFO "Capsule without Notes section" + return + fi + log INFO "Generating Notes index for $notes_dir" cat <<NOTES > "$notes_dir/index.gmi.tmp" |
