From 4b9cddca7f0f75e321319c79e94b3af3ce37e5ef Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Mon, 10 Apr 2023 16:18:01 -0300 Subject: v2: to collection feed inside --- v2/src/bin/collection-for | 23 ++++++++++++----------- v2/src/bin/conf | 36 +++++++++++++++++++++++------------- v2/src/bin/feed | 2 +- v2/src/bin/index | 9 +++++++-- 4 files changed, 43 insertions(+), 27 deletions(-) (limited to 'v2/src/bin') diff --git a/v2/src/bin/collection-for b/v2/src/bin/collection-for index 87f1204..e46f345 100755 --- a/v2/src/bin/collection-for +++ b/v2/src/bin/collection-for @@ -71,16 +71,17 @@ eval "$(assert_arg "$FILE" 'FILE')" lang="$(lang-for "$FILE")" DIR="$(dirname "$FILE")" -if [ "$DIR" = "$CONTENT_PREFIX/$lang" ]; then - echo +PAGE="${FILE%.*}.page" + +if [ -e "$PAGE" ]; then + exit 1 else - NAME="$(basename "$DIR")" - NTH="$( - collections | - xargs -I% coll2path "$lang" % | - awk '{ print NR, substr($0, 1, length($0) - 1) }' | - grep " $NAME$" | - cut -d' ' -f1 - )" - collections | awk -vNTH="$NTH" 'NR == NTH' + collections | awk -v l="$lang" -v pre="$CONTENT_PREFIX" -v dir="$DIR" '{ + "coll2path " l " " $0 | getline coll_path + d = pre "/" l "/" coll_path + sub(/\/$/, "", d) + if (d == dir) { + print $0 + } + }' fi diff --git a/v2/src/bin/conf b/v2/src/bin/conf index 3b56dbd..9fb4664 100755 --- a/v2/src/bin/conf +++ b/v2/src/bin/conf @@ -118,10 +118,32 @@ done < "$FILENAME" | tee -a "$FILENAME".tmp rm -f "$FILENAME".tmp +lang="$(lang-for "$FILENAME")" +export lang +printf 'export lang="%s"\n' "$lang" + +cat src/lib/base."${lang:?}".conf +# shellcheck source=/dev/null +. src/lib/base."$lang".conf +if [ -z "${title:-}" ]; then + title="${site_name:?}" + printf 'export title="%s"\n' "$(printf '%s' "$title" | shesc)" +fi + + collection="$(collection-for "$FILENAME" ||:)" if [ -n "$collection" ]; then export collection printf 'export collection="%s"\n' "$collection" + + coll_path="$(coll2path "$lang" "$collection")" + feed_title="$(eval "echo \"\$feed_${collection}_title\"" | htmlesc)" + + collection_head_html="$(printf ' ' \ + "$(url-for "$lang/$coll_path")" \ + "$(htmlesc "$feed_title")" + )" + printf 'export collection_head_html="%s"\n' "$(shesc "$collection_head_html")" fi if [ -z "${layout:-}" ]; then @@ -142,21 +164,9 @@ if [ -z "${layout:-}" ]; then fi -lang="$(lang-for "$FILENAME")" -export lang -printf 'export lang="%s"\n' "$lang" - -cat src/lib/base."${lang:?}".conf -# shellcheck source=/dev/null -. src/lib/base."$lang".conf -if [ -z "${title:-}" ]; then - title="${site_name:?}" - printf 'export title="%s"\n' "$(printf '%s' "$title" | shesc)" -fi - if [ -r "$FILENAME".i18n ]; then translations_head="$(awk -F: -v lang="$lang" '$1 != lang{ - printf " \n", + printf " \n", $3, $1 }' "$FILENAME".i18n)" translations_body="$(cat <<-EOF diff --git a/v2/src/bin/feed b/v2/src/bin/feed index f55ba89..4e0d2f5 100755 --- a/v2/src/bin/feed +++ b/v2/src/bin/feed @@ -76,7 +76,7 @@ eval "$(assert_arg "$FILENAME" 'FILENAME')" now="$(date -uIs)" url_absolute="$(url-for "${FILENAME#"$CONTENT_PREFIX"/}" | absolute)" site_name_html="$(htmlesc "${site_name:?}")" -collection="$(sh src/bin/collection-for "$FILENAME")" +collection="$(collection-for "$FILENAME")" coll_path="$(coll2path "${lang:?}" "$collection")" collection_url_absolute="$(url-for "${lang:?}/$coll_path" | absolute)" feed_title_html="$(eval "echo \"\$feed_${collection}_title\"" | htmlesc)" diff --git a/v2/src/bin/index b/v2/src/bin/index index 36abd2e..6212544 100755 --- a/v2/src/bin/index +++ b/v2/src/bin/index @@ -85,11 +85,16 @@ index_category_title_html="$(eval "echo \"\$index_category_${collection}_title\" export url_absolute feed_url by_category_url title_html index_recent_title_html \ index_category_title_html +feed_title="$(eval "echo \"\$feed_${collection}_title\"")" +collection_head_html="$(printf ' ' \ + "$feed_url" \ + "$(htmlesc "$feed_title")")" + translations_head_html="$(langs | awk -v lang="${lang:?}" -v coll="$collection" '$0 != lang { "coll2path " $0 " " coll | getline coll_path "url-for " $0 "/" coll_path | getline url - printf " \n", + printf " \n", url, $0 }' )" @@ -103,7 +108,7 @@ translations_body_html="$(cat <<-EOF EOF )" -export translations_head_html translations_body_html +export collection_head_html translations_head_html translations_body_html -- cgit v1.2.3