stl-statilque-litterateur/var/lib/stl/scripts/manage__HTML
2022-08-23 16:48:33 +02:00

292 lines
8.9 KiB
Bash

#!/bin/bash
# Name: Statique Littérateur
# Type: Manage HTML template
# file: manage__HTML
# Folder: /var/lib/stl/scripts/
# By echolib (XMPP: im@echolib.re)
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#------------
# funny stats
#------------
# lines: 292
# functions: 7
#-----------------------------------------------------------------------
#**********************************************************************
#======================================================================
# HTML code for <header>
# You can edit this function
# header.html is used in create_HTML_page
#======================================================================
create__HTML_header() {
cat <<EOHEADER
<header id="${domain_css}_banner">
<div id="${domain_css}_site-logo">
<a href="/">
<img src="${sub_genuri_srv}template/$domain_logo"
alt="Logo: $domain_title"
title="Logo: $domain_title"/>
</a>
</div>
<div id="${domain_css}_site-title">
<h1 id="${domain_css}_site-name">
<a href="/"
title="$stl_welcome $domain_title">
$domain_title
</a>
</h1>
<h2 id="${domain_css}_site-description">$domain_about</h2>
</div>
</header>
EOHEADER
}
#======================================================================
# HTML code for <footer>
# Do not edit this function
# footer.html is created - IF NOT EXISTS
# Uri: $domain_dir_wip_tpl/footer.html
# (i.e. /var/www/DOMAIN/wip/template/)
#======================================================================
create__HTML_footer() {
cat <<EOFOOTER > "$domain_dir_wip_tpl/footer.html"
<footer id="${domain_css}_footer">
<h1>$stl_about $domain_title</h1>
<div id="${domain_css}_footer-infos">
<p>$site_about<p>
</div>
<div id="${domain_css}_footer-about">
<ul>
<li><a href="$domain_url"><b>$domain_title</b></a>: $domain_about</li>
<li>Contact: $domain_mail</li>
<li>Copyright: $domain_cr</li>
<li>$stl_gen: <a href="https://git.a-lec.org/echolib/stl.git" target="_blank"><b>STL: Statique Littérateur</b></a></li>
<li>RSS: <a type="application/rss+xml" href="$domain_url/rss.xml">$domain_url/rss.xml</a></li>
</ul>
</div>
</footer>
EOFOOTER
}
#======================================================================
# HTML code for <footer>
# Do not edit this function
# metas.html is created - IF NOT EXISTS
# Uri: $domain_dir_wip_tpl/metas.html
# (i.e. /var/www/DOMAIN/wip/template/)
#======================================================================
create__HTML_metas() {
cat <<EOMETAS > "$domain_dir_wip_tpl/metas.html"
<meta charset="UTF-8" />
<meta name='viewport' content="width=device-width, initial-scale=1.0">
<meta name='robots' content="all">
<meta name='medium' content='website'>
<meta name='revisit-after' content="3 days">
<meta name='language' content="$domaine_lang">
<meta name='reply-to' content="$domain_mail">
<meta name='copyright' content="$domain_cr">
EOMETAS
}
#======================================================================
# Translate some static words according to domain_lang
#======================================================================
create__HTML_translation() {
if [[ `grep -i "fr" <<<"$domain_lang"` ]];then
stl_welcome="Page d'accueil de"
stl_written="Écrit par"
stl_about=" À propos de"
stl_gen="Propulsé par"
stl_the="le"
stl_by="par"
stl_read="Lire l'article de"
stl_rss_info="Tous les titres de"
# Convert date from INT to shit FR format (Yes, i love it...)
stl_date_y=`awk -F- '{print $1}' <<<"$article_date"`
stl_date_m=`awk -F- '{print $2}' <<<"$article_date"`
stl_date_d=`awk -F- '{print $3}' <<<"$article_date"`
stl_date="$stl_date_d/$stl_date_m/$stl_date_y"
else
stl_welcome="Welcome page of"
stl_written="Written by"
stl_bout="About"
stl_gen="Generated with"
stl_the="The"
stl_by="by"
stl_read="Read the post of"
stl_rss_info="All titles from"
stl_date="${article_date}"
fi
}
#======================================================================
# Page Template
#======================================================================
create__HTML_page() {
create__HTML_translation
# Create HTML footer and metas if not exist
! [[ -f "$domain_dir_wip_tpl/metas.html" ]] \
&& create__HTML_metas
! [[ -f "$domain_dir_wip_tpl/footer.html" ]] \
&& create__HTML_footer
# Sync basis images, files
sync__files "$domain_dir_images/" \
"$domain_dir_wip_images/" \
"WIP"
sync__files "$domain_dir_files/" \
"$domain_dir_wip_files/" \
"WIP"
# Sync specific included files from article to wip/
get__article_files_sync WIP # in manage__publish
# Create HTML Page
cat <<EOPAGE > "$domain_dir_wip$article_uri_srv"
<!DOCTYPE html>
<html lang="${domain_lang: :2}">
<head>
$(cat "$domain_dir_wip_tpl/metas.html")
<meta name='generator' content="STL: Statique Littérateur">
<meta name='title' content="$article_title | $site_title">
<meta name='author' content="$article_author">
<meta name='description' content="$article_info">
<meta name='keywords' content="$domain_tags,$article_tags">
<meta name='search_date' content="$article_date">
<link rel="alternate" type="application/rss+xml" href="$domain_url/rss.xml" title="RSS: $stl_rss_info $domain_title" />
<link rel="stylesheet" media="screen" href="${sub_genuri_srv}template/styles.css" />
<link rel="shortcut icon" type="image/png" href="${sub_genuri_srv}template/favicon.png" />
<link rel='me' type='text/html' href="$domain_ext_url">
<title>$article_title - $domain_title</title>
</head>
<body id="${domain_css}_body $database_id">
$(create__HTML_header)
<section id="${domain_css}_page-wrapper">
<article id="${domain_css}_article ">
<div id="${domain_css}_metas">
<p id="${domain_css}_auteur">$stl_written <strong>$article_author</strong> $stl_the $stl_date</p>
</div>
$(cat "$article_tmp_post")
</article>
<aside id="${domain_css}_sidebar">
<div class="${domain_css}_wrapper" role="navigation">
<nav id="${domain_css}_latest-posts">
<h1 class="${domain_css}_latest-posts">$domain_sidebar_title</h1>
<ul class="${domain_css}_latest-posts"
aria-label="$domain_sidebar_title">
<!--# include virtual="/template/sidebar.html" -->
</ul>
</nav>
</div>
</aside>
</section>
$(cat "$domain_dir_wip_tpl/footer.html")
</body>
</html>
EOPAGE
}
#======================================================================
# ATOM/RSS Creator
# File is at root wip server ; filename=rss.xml
# reverse sort time from DB | newest first
#======================================================================
create__RSS_feed() {
create__HTML_translation
rss_file="$domain_dir_wip/rss.xml"
cat <<EORSS > "$rss_file"
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>$domain_title - $domain_name - Flux RSS 2.0</title>
<link>$domain_url</link>
<description>$stl_rss_info $domain_title</description>
<language>$domain_lang</language>
<lastBuildDate>$(date)</lastBuildDate>
<copyright>$domain_cr</copyright>
<webMaster>$domain_mail</webMaster>
<generator>STL: Statique Littérateur</generator>
EORSS
while IFS=: read -r 'file' 'timestamp'
do
source "$file"
! [[ $article_wip_hash -gt 0 ]] \
&& continue
cat <<EOITEM >> "$rss_file"
<item>
<title>$article_title</title>
<link>$domain_url$article_uri_srv</link>
<guid>$domain_url$article_uri_srv</guid>
<pubDate>$(date -d @$article_timestamp)</pubDate>
<description>$article_about</description>
<author>$article_author</author>
</item>
EOITEM
done < <(grep -H "article_timestamp" "$domain_db_articles/"*.db \
| sort -t= -k2r)
cat <<EORSS >> "$rss_file"
</channel>
</rss>
EORSS
this_article="$rss_file"
log__add -i -M RSS "Created feed"
}
#======================================================================
# Article Item for sidebar
# Called from sidebar__create_HTML_item() in manage__sidebar
# $1: file ($sidebar_HTML_item)
#======================================================================
create__HTML_sidebar_item() {
create__HTML_translation
cat <<EOSIDEBARITEM > "$1"
<li class="${domain_css}_list-post-item">
<a href="$article_uri_srv"
class="${domain_css}_list-post-link"
title="$stl_read $article_author: $article_title">
<span class="${domain_css}_list-post-title">$article_title</span>
<div class="${domain_css}_list-post-metas">
$stl_the $stl_date $stl_by $article_author
</div>
<div class="${domain_css}_list-post-info">
$article_about
</div>
</a>
</li>
EOSIDEBARITEM
}