diff options
| author | Paul Buetow <paul@buetow.org> | 2023-03-12 18:04:36 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-03-12 18:04:36 +0200 |
| commit | 706e67ede63b3ff45707e6299c06b50e94e5ecf4 (patch) | |
| tree | ee7725cd0d295b12bc53eeede31d2ddc9cd6f7a6 | |
| parent | fddc47943377cb2907cedb9f9ab7cb09fce63e57 (diff) | |
make meta cache redundant
| -rw-r--r-- | README.md | 4 | ||||
| -rwxr-xr-x | gemtexter | 5 | ||||
| -rw-r--r-- | lib/atomfeed.source.sh | 123 |
3 files changed, 54 insertions, 78 deletions
@@ -44,7 +44,6 @@ You will notice soon that all site content is located in `../foo.zone-content/` ../foo.zone-content/gemtext ../foo.zone-content/html ../foo.zone-content/md -../foo.zone-content/meta ``` ### Alternative config file path @@ -63,7 +62,6 @@ Whereas you only want to edit the content in the `gemtext` folder directly. The * `gemtext`: The Gemini Gemtext markup files of the internet site. * `html`: The XHTML version of it. * `md`: The Markdown version of it. -* `meta`: Some metadata of all Gemtext blog posts. It's used by `gemtexter` internally for Atom feed generation. * `cache`: Some volatile cache data for speeding up Atom feed generation. ### Special HTML configuration @@ -90,8 +88,6 @@ A subsequent `./gemtexter --generate` will then detect the new post and link it Once all of that is done, the `gemtexter` script will convert the new post (plus all the indices and the Atom feed) to the other formats, too (e.g. HTML, Markdown). -You can also have a look at `$BASE_CONTENT_DIR/meta/gemfeed`. There is a metafile for each blog post stored. These metafiles are required for the generation of the Atom feed. You can edit these metafiles manually and run `./gemtexter --generate` or `./gemtexter --feed` again if you want to change some of the Atom feed content. - ## Drafting a blog post before publishing it If you don't want to publish your article yet (e.g. don't advertise it on the Gemfeed and Atom feed yet), you can draft your article in `./gemtext/gemfeed/DRAFT-article-title-dash-separated.gmi` and when invoke `./gemtexter --draft` to generate the outputs. Once you want to publish your draft just rename `DRAFT` with the publishing date `YYYY-MM-DD` and from there everything works normally. @@ -1,12 +1,13 @@ #!/usr/bin/env bash # # The Gemtexter blog engine and static site generator -# by Paul Buetow 2021, 2022 +# by Paul Buetow 2021, 2022, 2023 declare -r ARG="$1"; shift declare CONTENT_FILTER="$1"; shift declare -r VERSION=1.2.0 declare -r VERSION_DESCR=develop +declare -r DATE_FORMAT='--iso-8601=seconds' declare DATE=date declare SED=sed declare GREP=grep @@ -85,7 +86,7 @@ setup () { The content base directory, does not exist. Run the following to create it, it also adds some sample Gemtext content: - mkdir -p $CONTENT_BASE_DIR/{meta,md,html} + mkdir -p $CONTENT_BASE_DIR/{md,html} git clone --branch content-gemtext https://codeberg.org/snonux/foo.zone $CONTENT_BASE_DIR/gemtext rm -Rf $CONTENT_BASE_DIR/gemtext/.git diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh index 785246d..6be22a2 100644 --- a/lib/atomfeed.source.sh +++ b/lib/atomfeed.source.sh @@ -1,37 +1,3 @@ -# Retrieve meta data of a given blog post. Generate new meta info if not yet exists. -atomfeed::meta () { - local -r gmi_file_path="$1"; shift - local -r meta_file=$($SED 's|gemtext|meta|; s|.gmi$|.meta|;' <<< "$gmi_file_path") - - log VERBOSE "Generating meta info for post $gmi_file_path" - - local -r meta_dir=$(dirname "$meta_file") - if [[ ! -d "$meta_dir" ]]; then - mkdir -p "$meta_dir" - fi - - if [ ! -f "$meta_file" ]; then - # Extract first heading as post title. - local title=$($SED -n '/^# / { s/# //; p; q; }' "$gmi_file_path" | tr '"' "'") - # Extract first paragraph from Gemtext - local summary=$($SED -n '/^[A-Z]/ { p; q; }' "$gmi_file_path" | tr '"' "'") - # Extract the date from the file name. - local filename_date=$(basename "$gmi_file_path" | cut -d- -f1,2,3) - local date=$($DATE --iso-8601=seconds --date "$filename_date $($DATE +%H:%M:%S)") - - cat <<META | tee "$meta_file" -local meta_date="$date" -local meta_author="$AUTHOR" -local meta_email="$EMAIL" -local meta_title="$title" -local meta_summary="$summary. .....to read on please visit my site." -META - return - fi - - cat "$meta_file" -} - atomfeed::_from_cache () { local -r gmi_file_path="$1"; shift local -r cache_file_path="$1"; shift @@ -82,27 +48,23 @@ atomfeed::content () { # Generate an atom.xml feed file. atomfeed::generate () { local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" + if [ ! -d "$gemfeed_dir" ]; then return - fi - - if [ -n "$CONTENT_FILTER" ]; then + elif [ -n "$CONTENT_FILTER" ]; then log WARN "Not generating Atom feed in filter mode" 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" - cat <<ATOMHEADER > "$atom_file.tmp" <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> - <updated>$now</updated> + <updated>$($DATE $DATE_FORMAT)</updated> <title>$DOMAIN feed</title> <subtitle>$SUBTITLE</subtitle> <link href="gemini://$DOMAIN/gemfeed/atom.xml" rel="self" /> @@ -111,37 +73,7 @@ atomfeed::generate () { ATOMHEADER while read -r gmi_file; do - # Load cached meta information about the post. - source <(atomfeed::meta "$gemfeed_dir/$gmi_file") - - # Get HTML content for the feed - local content="$(atomfeed::content "$gemfeed_dir/$gmi_file")" - - assert::not_empty meta_title "$meta_title" - assert::not_empty meta_date "$meta_date" - assert::not_empty meta_author "$meta_author" - assert::not_empty meta_email "$meta_email" - assert::not_empty meta_summary "$meta_summary" - assert::not_empty content "$content" - - cat <<ATOMENTRY >> "$atom_file.tmp" - <entry> - <title>$meta_title</title> - <link href="gemini://$DOMAIN/gemfeed/$gmi_file" /> - <id>gemini://$DOMAIN/gemfeed/$gmi_file</id> - <updated>$meta_date</updated> - <author> - <name>$meta_author</name> - <email>$meta_email</email> - </author> - <summary>$meta_summary</summary> - <content type="xhtml"> - <div xmlns="http://www.w3.org/1999/xhtml"> - $content - </div> - </content> - </entry> -ATOMENTRY + atomfeed::_entry "$gemfeed_dir" "$gmi_file" "$atom_file.tmp" done < <(gemfeed::get_posts | head -n $ATOM_MAX_ENTRIES) cat <<ATOMFOOTER >> "$atom_file.tmp" @@ -159,6 +91,53 @@ ATOMFOOTER fi } +atomfeed::_entry () { + local -r gemfeed_dir="$1" + local -r gmi_file="$2" + local -r tmp_atom_file="$3" + + log INFO "Generating Atom feed entry for $gmi_file" + + # Get HTML content for the feed + local content="$(atomfeed::content "$gemfeed_dir/$gmi_file")" + assert::not_empty content "$content" + + # Extract first heading as post title. + local title=$($SED -n '/^# / { s/# //; p; q; }' "$gemfeed_dir/$gmi_file" | tr '"' "'") + assert::not_empty title "$title" + + # Extract first paragraph from Gemtext as the summary. + local summary=$($SED -n '/^[A-Z]/ { p; q; }' "$gemfeed_dir/$gmi_file" | tr '"' "'") + assert::not_empty summary "$summary" + + # Extract the date from the file name. + local publishing_date=$($SED -n '/^> Published at / { s/.*Published at //; s/;.*//; p; }' "$gemfeed_dir/$gmi_file") + if [ -z "$publishing_date" ]; then + publishing_date=$($DATE $DATE_FORMAT -r "$gemfeed_dir/$gmi_file") + log WARN "No publishing date specified for $gmi_file, assuming $publishing_date" + fi + assert::not_empty publishing_date "$publishing_date" + + cat <<ATOMENTRY >> "$tmp_atom_file" + <entry> + <title>$title</title> + <link href="gemini://$DOMAIN/gemfeed/$gmi_file" /> + <id>gemini://$DOMAIN/gemfeed/$gmi_file</id> + <updated>$publishing_date</updated> + <author> + <name>$AUTHOR</name> + <email>$EMAIL</email> + </author> + <summary>$summary</summary> + <content type="xhtml"> + <div xmlns="http://www.w3.org/1999/xhtml"> + $content + </div> + </content> + </entry> +ATOMENTRY +} + atomfeed::_xmllint () { local -r atom_feed="$1" |
