360 lines
10 KiB
Bash
360 lines
10 KiB
Bash
#!/bin/bash
|
|
# file: gsl__page_creator
|
|
# Folder: /var/lib/gsl/scripts
|
|
# By echolib
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
#----------------------------------------------------------------------
|
|
# --------------------------------------------------
|
|
# From: gsl__all_makers | Create HTML Page
|
|
# --------------------------------------------------
|
|
#----------------------------------------------------------------------
|
|
|
|
#----------------------------------------------------------------------
|
|
# MAIN
|
|
#----------------------------------------------------------------------
|
|
gsl__page_creator() {
|
|
#gsl__page_prepare_datas
|
|
gsl__check_templates
|
|
gsl__html_meta_head
|
|
gsl__page_create
|
|
cat -n "$gsl_srv_wip_page"
|
|
}
|
|
|
|
#======================================================================
|
|
# Sync Files from Templates to webserver
|
|
#======================================================================
|
|
gsl__srv_sync() {
|
|
# Sync Files and Folders
|
|
mkdir -p "$1"
|
|
for folder in `find $gsl_this_conf_domain/* -type d`
|
|
do
|
|
rsync -a --delete "$folder" "$1" && \
|
|
gsl__logs_print \
|
|
"$gsl_log_i" \
|
|
"Server" \
|
|
"Sync" \
|
|
"$folder" \
|
|
"$1"
|
|
done
|
|
}
|
|
|
|
#----------------------------------------------------------------------
|
|
# Get Datas for Post/Page
|
|
#----------------------------------------------------------------------
|
|
gsl__page_prepare_datas() {
|
|
# Set wip folder from domain
|
|
gsl_srv_wip="$gsl_site_server/$gsl_site_ndd/wip"
|
|
gsl_srv_www="$gsl_site_server/$gsl_site_ndd/www"
|
|
|
|
# Post or Page
|
|
case "$gsl_post_type" in
|
|
post)
|
|
gsl_srv_wip_page="$gsl_srv_wip/$gsl_header_slug/index.html"
|
|
gsl_srv_www_page="$gsl_srv_www/$gsl_header_slug/index.html"
|
|
gsl__check_srv_files "$gsl_srv_wip_page" wip
|
|
gsl__check_srv_files "$gsl_srv_www_page" www
|
|
gsl_uri=".."
|
|
;;
|
|
page)
|
|
gsl_srv_wip_page="$gsl_srv_wip/$gsl_header_slug.html"
|
|
gsl_srv_www_page="$gsl_srv_www/$gsl_header_slug.html"
|
|
gsl__check_srv_files "$gsl_srv_wip_page" wip
|
|
gsl__check_srv_files "$gsl_srv_www_page" www
|
|
gsl_uri="."
|
|
;;
|
|
esac
|
|
|
|
gsl_uri_site_logo="$gsl_uri/templates/$gsl_site_logo"
|
|
}
|
|
|
|
#----------------------------------------------------------------------
|
|
# Check if Post / Pages exists in server
|
|
#----------------------------------------------------------------------
|
|
gsl__check_srv_files() {
|
|
if [[ -f "$1" ]];then
|
|
gsl__logs_print \
|
|
"$gsl_log_i" \
|
|
"SRV" \
|
|
"$2" \
|
|
"$gsl_post_type $gsl_post exists" \
|
|
"$1"
|
|
else
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"SRV" \
|
|
"$2" \
|
|
"$gsl_post_type $gsl_post not yet created" \
|
|
"$1"
|
|
gsl_checker_war=true
|
|
fi
|
|
}
|
|
|
|
#======================================================================
|
|
# latest Posts listing Manager
|
|
#======================================================================
|
|
gsl__page_listing_create() {
|
|
# Check if Post is in list ; Status Made
|
|
gsl_checker_war=true
|
|
gsl_listing_file="$gsl_dir_domain_listings/$gsl_post.list"
|
|
|
|
if [[ `ls -1 "$gsl_listing_file"* 2>/dev/null` ]];then
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"Latest" \
|
|
"$gsl_post_list $gsl_post ; already added to Listing" \
|
|
"$gsl_dir_domain_listings/"
|
|
return
|
|
fi
|
|
|
|
case "$gsl_post_list" in
|
|
Pin)
|
|
gsl_listing_start_n=1
|
|
[[ $gsl_post_pin ]] \
|
|
&& sed -i "s|gsl_post_pin.*|gsl_post_pin=$gsl_header_title|" \
|
|
"$gsl_this_conf_domain/$gsl_find_domain.conf" \
|
|
|| echo "gsl_post_pin=$gsl_header_title" \
|
|
>> "$gsl_this_conf_domain/$gsl_find_domain.conf"
|
|
;;
|
|
Add)
|
|
# Check if a post is pinned
|
|
[[ $gsl_post_pin ]] \
|
|
&& gsl_listing_start_n=2 \
|
|
|| gsl_listing_start_n=1
|
|
;;
|
|
esac
|
|
|
|
gsl__page_listing_roller
|
|
gsl__page_listing_create_file "$gsl_listing_file.$gsl_listing_start_n"
|
|
|
|
cat `ls -1r "$gsl_dir_domain_listings/"*.list.*` \
|
|
> "$gsl_dir_domain_tpl/last-posts-list.html" \
|
|
&& gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"Latest" \
|
|
"Create Listing (Merged .list.*)"\
|
|
"$gsl_dir_domain_tpl/last-post-list.html"
|
|
}
|
|
|
|
#======================================================================
|
|
# Create HTML List from selected Post
|
|
#======================================================================
|
|
gsl__page_listing_create_file() {
|
|
cat << EOPostSide > "$1"
|
|
<li>
|
|
<span class="${gsl_site_css}_list-post-title">$gsl_header_title</span>
|
|
<div class="${gsl_site_css}_list-post-metas">Le $gsl_header_date par $gsl_header_author<div>
|
|
<div class="${gsl_site_css}_list-post-info">$gsl_header_info</div>
|
|
</li>
|
|
EOPostSide
|
|
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"Latest" \
|
|
"$gsl_post_list $gsl_post to Listing" \
|
|
"$1"
|
|
}
|
|
|
|
#======================================================================
|
|
# latest Posts listing Rolling
|
|
#======================================================================
|
|
gsl__page_listing_roller() {
|
|
|
|
gsl__page_listing_file_mv() {
|
|
for n in `seq $gsl_listing_start_n $(( gsl_listing_last_n )) | sort -r`
|
|
do
|
|
gsl_listing_this_post=`ls -1 "$gsl_dir_domain_listings/"*".list.$n"`
|
|
gsl_listing_tmp_no_n=`echo ${gsl_listing_this_post%.*}`
|
|
gsl_listing_new_post="$gsl_listing_tmp_no_n.$(( n + 1 ))"
|
|
|
|
mv "$gsl_listing_this_post" \
|
|
"$gsl_listing_new_post"
|
|
done
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"Latest" \
|
|
"Roll from Listing" \
|
|
"$gsl_dir_domain_listings/*.list.*"
|
|
}
|
|
|
|
# search for last listing number
|
|
gsl_listing_last=`
|
|
ls -1 "$gsl_dir_domain_listings/"*".list."* 2>/dev/null \
|
|
| tail -1`
|
|
|
|
if [[ $gsl_listing_last ]];then
|
|
|
|
# A Post is Pinned
|
|
if [[ $gsl_post_pin ]];then
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"Latest" \
|
|
"Remove Pin $gsl_listing_rm_post_name from Listing" \
|
|
"$gsl_listing_rm_post_uri"
|
|
fi
|
|
|
|
# Get Last listing number
|
|
gsl_listing_last_n=${gsl_listing_last: -1}
|
|
# Remove last file
|
|
if (( $gsl_listing_last_n == $gsl_list_max_posts ));then
|
|
gsl_listing_rm_post_uri=`
|
|
ls -1 "$gsl_dir_domain_listings/"*".list.$gsl_list_max_posts"`
|
|
gsl_listing_rm_post_name=`
|
|
basename "$gsl_listing_rm_post_uri" | awk -F"." '{print $1"."$2}'`
|
|
|
|
rm -f "$gsl_dir_domain_listings/"*".list.$gsl_list_max_posts" && \
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"Latest" \
|
|
"Remove $gsl_listing_rm_post_name from Listing" \
|
|
"$gsl_listing_rm_post_uri"
|
|
gsl_listing_last_n=4
|
|
fi
|
|
|
|
# Roll each ones + 1
|
|
gsl__page_listing_file_mv
|
|
|
|
fi
|
|
}
|
|
|
|
#----------------------------------------------------------------------
|
|
# Create Final HTML Post/Page
|
|
#----------------------------------------------------------------------
|
|
gsl__page_create() {
|
|
cat << EOPAGE > "$gsl_srv_wip_page"
|
|
<!DOCTYPE html>
|
|
<html lang="${gsl_site_lang: :2}">
|
|
<head>
|
|
`cat "$gsl_html_meta"`
|
|
</head>
|
|
|
|
<body id="${gsl_site_css}_$gsl_post_type">
|
|
|
|
`cat "$gsl_dir_domain_tpl/header.html"`
|
|
|
|
<section id="${gsl_site_css}_page-wrapper">
|
|
<article id="${gsl_site_css}_$gsl_header_slug">
|
|
|
|
<div id="${gsl_site_css}_metas">
|
|
<p id="${gsl_site_css}_auteur">Écrit par <strong>$gsl_header_author</strong> le $gsl_header_date</p>
|
|
</div>
|
|
|
|
`cat "$gsl_a11y_post"`
|
|
</article>
|
|
|
|
<aside id="${gsl_site_css}_sidebar">
|
|
<div class="${gsl_site_css}_wrapper" role="navigation">
|
|
<nav id="${gsl_site_css}_latest-posts">
|
|
<h1 class="${gsl_site_css}_latest-posts">Derniers articles</h1>
|
|
<ul aria-label="Liste d'Articles">
|
|
<!--# include file="$gsl_uri/templates/last-posts-list.html" -->
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
</aside>
|
|
</section>
|
|
|
|
`cat "$gsl_dir_domain_tpl/footer.html"`
|
|
|
|
</body>
|
|
</html>
|
|
EOPAGE
|
|
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"SRV" \
|
|
"wip" \
|
|
"$gsl_post_type $gsl_post created" \
|
|
"$gsl_srv_wip_page"
|
|
gsl_checker_war=true
|
|
|
|
# No more needed html meta file
|
|
rm -f "$gsl_html_meta"
|
|
}
|
|
|
|
#----------------------------------------------------------------------
|
|
# Create META head for Post/Page
|
|
#----------------------------------------------------------------------
|
|
gsl__html_meta_head() {
|
|
# Create file with metas to be included in Post/Page
|
|
gsl_html_meta=`mktemp`
|
|
cat << EOMETAS >> "$gsl_html_meta"
|
|
<meta charset="UTF-8" />
|
|
<meta name='viewport' content="width=device-width, initial-scale=1.0">
|
|
<meta name='robots' content="all">
|
|
<meta name='generator' content="GSL: Statique Littérateur">
|
|
<meta name='medium' content='website'>
|
|
<meta name='revisit-after' content="3 days">
|
|
|
|
<title>$gsl_header_title - $gsl_site_title</title>
|
|
<link rel="stylesheet" "media="screen" href="$gsl_uri/templates/styles.css" />
|
|
<link rel="shortcut icon" type="image/png" href="$gsl_uri/templates/favicon.png" />
|
|
<link rel='me' type='text/html' href="$gsl_site_auth_url">
|
|
|
|
<meta name='language' content="$gsl_site_lang">
|
|
<meta name='reply-to' content="$gsl_site_mail">
|
|
<meta name='copyright' content="$gsl_site_cr">
|
|
<meta name='title' content="$gsl_header_title - $gsl_site_title">
|
|
<meta name='author' content="$gsl_header_author">
|
|
<meta name='description' content="$gsl_header_info">
|
|
<meta name='keywords' content="$gsl_site_keys,$gsl_header_tags">
|
|
<meta name='search_date' content="$gsl_header_date">
|
|
EOMETAS
|
|
}
|
|
|
|
#-----------------------------------------------------------------------
|
|
# Create Generic Header
|
|
#-----------------------------------------------------------------------
|
|
gsl__html_header() {
|
|
cat << EOHEADER >> "$gsl_dir_domain_tpl/header.html"
|
|
<header id="${gsl_site_css}_banner">
|
|
<div id="${gsl_site_css}_site-logo">
|
|
<a href="/">
|
|
<img src="$gsl_uri_site_logo"
|
|
alt="Logo de $gsl_site_title"
|
|
title="Logo de $gsl_site_title"/>
|
|
</a>
|
|
</div>
|
|
<section id="${gsl_site_css}_site-titles">
|
|
<h1 id="${gsl_site_css}_site-name">
|
|
<a href="/"
|
|
title="Page d'accueil de $gsl_site_title">
|
|
$gsl_site_title
|
|
</a>
|
|
</h1>
|
|
<h2 id="${gsl_site_css}_site-description">$gsl_site_info</h2>
|
|
</section>
|
|
</header>
|
|
EOHEADER
|
|
}
|
|
|
|
#-----------------------------------------------------------------------
|
|
# Create Generic Footer
|
|
#-----------------------------------------------------------------------
|
|
gsl__html_footer() {
|
|
cat << EOFOOTER >> "$gsl_dir_domain_tpl/header.html"
|
|
<footer id=${gsl_site_css}_footer">
|
|
</footer>
|
|
EOFOOTER
|
|
}
|
|
|
|
#-----------------------------------------------------------------------
|
|
# Check for files in templates folder
|
|
#-----------------------------------------------------------------------
|
|
gsl__check_templates() {
|
|
#echo "D> $gsl_dir_domain_tpl"
|
|
# Create generic HEADER if not exists
|
|
! [[ "$gsl_dir_domain_tpl/header.html" ]] \
|
|
&& gsl__html_header
|
|
|
|
# Create generic FOOTER if not exists
|
|
! [[ "$gsl_dir_domain_tpl/footer.html" ]] \
|
|
&& gsl__html_footer
|
|
}
|