[WIP] Initial commit for qsgen3

This commit is contained in:
2025-05-30 20:37:56 +02:00
parent 106b66753f
commit 75105821fd
138 changed files with 12471 additions and 7 deletions

View File

@ -0,0 +1,101 @@
VERSION="0.4.3"
QSGEN="Quick Site Generator 2"
globaldebug=false
fpath=(${HOME}/bin/include/common ${HOME}/bin/include/qsgen2/lang $fpath)
autoload include
autoload zini
include common/colors
echo "${magenta}${blue_bg} ${QSGEN} ${end}${bold_white}${blue_bg}${VERSION} ${end}"
if [[ -f $(pwd)/config ]]; then
if (${globaldebug}); then echo "${red}Config file found and sourced${end}\n${yellow} - $(pwd)/config${end}"; fi
zini $(pwd)/config
else
echo "${red}Cannot find configuration file.${end}"
echo "${yellow} - Please create the file 'config' in your project directory.${end}"
echo "${yellow} - See 'config.example' in the git source tree.${end}"
exit
fi
typeset -A qsgenlang
lang_found=false
for dir in $fpath; do
if [[ -f "${dir}/${config[project_lang]}" ]]; then
source "${dir}/${config[project_lang]}"
lang_found=true
break
fi
done
if [[ ${lang_found} == "false" ]]; then
echo "Defined language, ${config[project_lang]}, not found. Using en_US."
source "${HOME}/bin/include/qsgen2/lang/en_US"
fi
if (${globaldebug}); then
qsconfig=$( cat $(pwd)/config | grep -v \# | awk '{print substr($0, index($0, " ") + 1)}' )
echo "Content of Config file"
for qslines in ${qsconfig}
do
echo "${yellow}${qslines}${end}"
done
fi
if [[ "$1" == "version" || "$1" == "-v" || "$1" == "--version" ]]; then
_version ${0:t}
elif [[ "$1" == "help" || "$1" == "-h" || "$1" == "--help" ]]; then
_help ${0:t}
fi
blog_cache_file="${config[project_root]}/.blog_cache"
pages_cache_file="${config[project_root]}/.pages_cache"
if [[ ! ${config[project_generator]} ]] || [[ -d $(pwd)/.git ]]; then
_msg debug "_qsgen2_msg_3"
exit
fi
if [[ ${config[project_generator]} == "native" ]]; then
engine=_qstags
export file_ext="qst"
elif [[ ${config[project_generator]} == "markdown" ]]; then
if [[ ! -f /usr/local/bin/pandoc ]]; then
_msg other "_qsgen2_msg_4"
_msg other "https://github.com/jgm/pandoc/releases"
exit
else
engine="/usr/local/bin/pandoc"
engine_opts=
export file_ext="md"
fi
else
_msg debug "_qsgen2_msg_5"
exit
fi
if (${globaldebug}); then _msg debug "_qsgen2_msg_6"; fi
builtin cd ${config[project_root]}
zmodload zsh/files
zmodload zsh/datetime
zmodload zsh/regex
export today=$(strftime "%Y-%m-%d - %T")
export blogdate=$(strftime "%a-%Y-%b-%d")
case ${1} in
force)
_msg sub "_qsgen2_msg_2"
: >| "$blog_cache_file"
: >| "$pages_cache_file"
;;
sitemap)
_msg sub "Updating sitemaps"
export sitemap_force=true
_sitemap
exit
;;
*)
;;
esac
_blogs
_pages
_sitemap

View File

@ -0,0 +1,142 @@
#!/usr/bin/zsh
###############################################################################
###############################################################################
#
# Quick Site Generator 2 is a static website generator inspired by Nikola.
# It is written for the Z shell (zsh) because that's what I use and also because
# I like it better than Bash.
#
# This script is an almost complete rewrite of my old script because it became
# overly complicated and had way too many bugs, even though it worked on simple
# sites.
#
# https://github.com/kekePower/qsgen2/
#
###############################################################################
############################################################################### # Sat-2024-02-24
# Set to true or false
# This will show debug information from every function in this script
# You can also set debug=true in a single function if you want to debug only that specific one.
# Use Zsh fpath to set the path to some extra functions
# In this case, let's load the 'include' function
# Including some colors to the script
# Check for, and source, the config file for this specific website
# Load language as defined in config
# echo "Language file: ${dir}/${config[project_lang]}"
# Fall back to en_US if defined language isn't found
##
# @brief Display a message with specific formatting based on message type.
# @param type The type of message (e.g., std, info, debug, etc.)
# @param ... The keys or additional strings to be formatted and displayed.
##
# @brief Display the version information of the script.
# @param ... Additional arguments (unused in this function).
##
# @brief Display help information for the script.
# @param ... Additional arguments (unused in this function).
# Define cache files for blogs and pages
# Let's check if qsgen2 can generate this site by checking if 'generator' is available
# We define the variable 'engine' based on what's in the 'config' file.
# Usage: ${engine} ${1} - Where 1 is the file you want to convert
# Usage: ${engine} ${1} - Where 1 is the file you want parsed
##
# @brief Run the configured engine to process the input file.
# @param input The input file to be processed.
# Loading Zsh modules
# Let's put these here for now.
# Let's create arrays of all the files we'll be working on
##
# @brief List all page files and store them in an array.
##
# @brief List all blog files and store them in an array.
##
# @brief Cache the state of blog files and identify changes.
##
# @brief Cache the state of page files and identify changes.
# @return Array of pages to be processed.
##
# @brief Update #updated and #version tags in the provided content.
# @param content The content to be updated.
# @return The updated content.
##
# @brief Update #updated and #version tags in the provided file.
# @param file_path The path to the file to be updated.
##
# @brief Convert the filename to lowercase and replace spaces with dashes.
# @param filename The original filename.
# @return The modified filename.
##
# @brief Generate all new and updated pages.
##
# @brief Generate or update blog files or export metadata based on argument.
##
# @brief Generate the file blog/index.tmp.html.
##
# @brief Generate the www_root/blog/index.html file.
##
# @brief Add the blog list to the index file if blog_in_index is true.
##
# @brief Generate the sitemap files if conditions are met.
##
# @brief Convert #link tags to clickable HTML links.
# @param content The content containing #link tags.
# @return The content with #link tags replaced by HTML links.
##
# @brief Convert #showimg tags to HTML img tags.
# @param content The content containing #showimg tags.
# @return The content with #showimg tags replaced by HTML img tags.
##
# @brief Embed a YouTube video in the provided content.
# @param content The content containing #ytvideo tags.
# @return The content with #ytvideo tags replaced by YouTube iframe embeds.
##
# @brief Remove leftover tags from the content.
# @param content The content to be cleaned.
# @return The cleaned content.
##
# @brief Convert QStags to HTML using Perl.
# @param content The content containing QStags.
# @return The content with QStags converted to HTML.
##
# @brief Convert QStags to HTML using Zsh regex module.
# @param content The content containing QStags.
# @return The content with QStags converted to HTML. # Truncate the blog cache before doing update # Truncate the page cache before doing update
# Nothing