Update Quick Site Generator 2 README and qsgen2 script

- Update to version 0.3.5
- Updated the link to Zsh in the README file.
- Made changes to the _pages function in the qsgen2 script to use Zsh built-in functions for finding the page title.
- Added support for finding the page title in markdown files in the _pages function.
- Added support for finding the blog title in markdown files in the _blogs function.
This commit is contained in:
Stig-Ørjan Smelror 2024-02-10 21:15:24 +01:00
parent 9eafc715b6
commit 12f36071df
5 changed files with 282 additions and 7 deletions

View File

@ -1,7 +1,7 @@
<img src="qsg2-square.png" width="150" align="left"> <img src="qsg2-square.png" width="150" align="left">
# Quick Site Generator 2 # Quick Site Generator 2
Quick Site Generator 2 is a static website generator inspired by [Nikola](https://github.com/getnikola/nikola) and written using Zsh. Quick Site Generator 2 is a static website generator inspired by [Nikola](https://github.com/getnikola/nikola) and written for [Zsh](https://zsh.sourceforge.io/).
<br><br> <br><br>
@ -13,7 +13,7 @@ It all started with a simple script I wrote that I called ```myjourney``` to wri
So I started to write another script I aptly called ```generate```.This also worked really great. It was, however, very limited and not very portable. So I started to write another script I aptly called ```generate```.This also worked really great. It was, however, very limited and not very portable.
Then this script was born. It has the same ideas as the first two, but is an almost complete rewrite of ```generate```. It does, however, use some of the same functions and is also more portable. The next steps is to try to use more of the Zsh modules instead of relying on external tools like Perl, sed and awk. In other words, a work in progress. Then this script was born. It has the same ideas as the first two, but is an almost complete rewrite of ```generate```. It does, however, use some of the same functions and is also more portable. The next steps is to try to use more of the Zsh modules instead of always relying on external tools like Perl, sed and awk. In other words, a work in progress.
## What is qsgen2? ## What is qsgen2?

106
en_US Normal file
View File

@ -0,0 +1,106 @@
# Usage: _msg <type> "<message>"
_msg info "Usage: qsgen2 add \"Site Name\" \"/path/to/project\""
_msg sub "- Forced Update: Generating Everything"
_msg debug "* ${0:t} cannot parse this site. Exiting. *"
_msg other "Please install Pandoc."
_msg other "https://github.com/jgm/pandoc/releases"
_msg debug "No valid generator found. Are you sure you've selected the correct generator in 'config'?"
if (${globaldebug}); then _msg debug "Using the ${generator} engine for files: ${file_ext}"; fi
if ${debug}; then _msg debug "_list_pages: No Pages found with ext ${file_ext}."; fi
if ${debug}; then _msg debug "_list_pages: Adding file to array: ${file}"; fi
if ${debug}; then _msg debug "_list_blogs: No blog files found."; fi
if ${debug}; then _msg debug "_list_blogs: Adding file to array: $file"; fi
if (${debug}) _msg debug "_blog_cache: HASH VALUE: ${blog_cache[${name}]}"
if (${debug}) _msg debug "1. _blog_cache: ${blog_file}"
if (${debug}) _msg debug "2. _blog_cache: current_cache: ${current_hash}"
if (${debug}) _msg debug "3. _blog_cache: new_cache_file: ${blog_file}$"
if (${debug}) _msg debug "4. _blog_cache: new_current_cache: ${current_hash}"
if (${debug}) _msg debug "PAGES HASH VALUE: ${pages_cache[${name}]}"
if (${debug}) _msg debug "1. pages_cache: ${pages_cache[$file]}"
if (${debug}) _msg debug "1. _pages_cache: current_cache: ${current_hash}"
if (${debug}) _msg debug "2. _pages_cache: pages_file: ${pages_cache[$file]}"
if (${debug}) _msg debug "2. _pages_cache: current_cache: ${current_hash}"
if (${debug}); then _msg debug "_last_updated: Setting date and version in footer"; fi
if (${debug}); then _msg debug "_last_updated: ${upd_msg}"; fi
local upd_msg="Last updated ${today} by <a href=\"https://blog.kekepower.com/qsgen2.html\">${QSGEN} ${VERSION}</a>"
-e "s|#updated|${upd_msg}|")
if (${debug}); then _msg debug "_f_last_updated: Setting date and version in footer of file ${1}"; fi
if (${debug}); then _msg debug "_f_last_updated: ${upd_msg}"; fi
local upd_msg="Last updated ${today} by <a href=\"https://blog.kekepower.com/qsgen2.html\">${QSGEN} ${VERSION}</a>"
-e "s|#updated|${upd_msg}|" \
if (${debug}) _msg debug "_pages: Running function _pages_cache"
_msg sub "* You do not have any pages *"
_msg main "Generating Pages"
if (${debug}) _msg debug "_pages: pages_array is not empty"
if (${debug}) _msg debug "_pages: Setting Pages template"
_msg info "Unable to find the Pages template: ${pages}"
if (${debug}) _msg debug "_pages: Reading Pages template into pages_tpl"
_msg std "- Generating Page: ${pages_in_array%.*}.html"
if (${debug}) _msg debug "_pages: Loading page_content once - ${pages_in_array}"
if (${debug}) _msg debug "_pages: Grepping for page_title"
if (${debug}) _msg debug "_pages: ${page_title}"
if (${debug}) _msg debug "_pages: Removing #title line from page_content"
if (${debug}) _msg debug "_pages: Running engine on ${pages_in_array}"
if (${debug}) _msg debug "_pages: Checking for #link, #showimg and #ytvideo in page_content"
if (${debug}) _msg debug "_pages: #link is present, run _link: page_content"
if (${debug}) _msg debug "_pages: #showimg is present, run _image: page_content"
if (${debug}) _msg debug "_pages: #ytvideo is present, run _youtube: page_content"
if (${debug}) _msg debug "_pages: Replacing BODY with page_content in pages_tpl"
if (${debug}) _msg debug "_pages: Replacing #pagetitle, #tagline and #sitename in pages_tpl"
if (${debug}) _msg debug "_pages: _last_updated in pages_tpl"
if (${debug}) _msg debug "_pages: Lowercase filnames, always"
if (${debug}) _msg debug "_pages: Running _cleanup"
# _msg std "Writing ${www_root}/${pages_title_lower%.*}.html to disk."
if (${debug}) _msg sub "- Parsing ${pages_in_array}"
if (${debug}) _msg sub "- blog_in_index = ${blog_in_index}"
if (${debug}) _msg sub "- Listing blog temp file:"
_msg std "Updating index.html with new blog posts"
if (${debug}) _msg sub "- Parsing ${pages_in_array}"
if (${debug}) _msg sub "- blog_in_index = ${blog_in_index}"
if (${debug}) _msg sub "- Listing blog temp file:"
_msg sub "- No new or updated Pages found"
if (${debug}) _msg debug "_blogs: Running function _list_blogs"
_msg sub "* You do not have any blogs *"
_msg main "Generating Blogs"
if (${debug}) _msg debug "_blogs: Running function _blog_cache"
_msg info "Unable to find theme template for Blogs."
if (${debug}) _msg debug "_blogs: Processing pre-data for ${blog}"
_msg debug "_blogs: DATE metadata missing in ${blog}."
if (${debug}) _msg debug "_blogs: Adding data for ${blog} to array to export"
if (${debug}) _msg debug "_blogs: Processing ${blog}"
_msg std "- Generating Blog: ${blog_index}.html"
if (${debug}) _msg debug "_blogs: Processing substitutes in ${blog}"
if (${debug}) _msg debug "_blogs: Running function $engine for ${blog}"
if (${debug}) _msg debug "_blogs: Checking for #link, #showimg and #ytvideo in blog_content"
if (${debug}) _msg debug "_blogs: #link is present, run _link: blog_content"
if (${debug}) _msg debug "_blogs: #showimg is present, run _link: blog_content"
if (${debug}) _msg debug "_blogs: #ytvideo is present, run _link: blog_content"
if (${debug}) _msg debug "_blogs: Replacing tagline, sitename and pagetitle"
if (${debug}) _msg debug "_blogs: Creating directoty ${www_root}/${blog_dir}"
if (${debug}) _msg debug "_blogs: Writing blog to disk: ${www_root}${blog_url}"
_msg sub "- No new or updated Blogs found"
if (${debug}) _msg sub "* _blogs: Running _blog_idx_for_index"
if (${debug}) _msg sub "* _blogs: Running _blog_index"
_msg sub "- Populating ${project_dir}/blog/index.tmp.html"
if (${debug}) _msg debug "_blog_idx_for_index: Initiating function"
if (${debug}) _msg debug "_blog_idx_for_index: BLOG_META_STR_ARRAY: ${BLOG_META_STR_ARRAY[@]}"
if (${debug}) _msg debug "_blog_idx_for_index: meta_str from BLOG_META_STR_ARRAY from _blogs"
if (${debug}) _msg debug "_blog_idx_for_index: ${meta_str}"
if (${debug}) _msg debug "_blog_idx_for_index: Iterate over each component and extract information"
if (${debug}) _msg debug "_blog_idx_for_index: Running ${engine} on content to catch QStags in Ingress"
if (${debug}) _msg debug "_blog_idx_for_index: Writing _blog_idx_for_index to file: ${project_dir}/blog/index.tmp.html"
if (${debug}) _msg debug "_blog_idx_for_index: blog_list_content = ${blog_list_content}"
if (${debug}) _msg debug "Running function _blog_index"
if (${debug}) _msg debug "_blog_index: blog_in_index = ${blog_in_index}"
_msg std "- Generating the Blog index file"
if (${debug}) _msg debug "_add_blog_list_to_index: Inserting blog list to index.html"
_msg main "Generating Sitemap"
if (${debug}); then _msg debug "Sitemap generated at ${sitemap_file}"; fi
if (${debug}) _msg debug "_link: URL_MAIN(line): ${line}"
if (${debug}) _msg debug "_link_ URL: ${url_dest}"
if (${debug}) _msg debug "_link: Text: ${url_txt}"
if (${debug}) _msg debug "_image: Processing line: ${line}"
if (${debug}) _msg debug "_youtube: Processing line: ${line}"
if (${debug}) _msg debug "_cleanup: Cleaning up tags in content"
_msg debug "_html: Converting QStags in content"
_msg debug "_html: Converting QStags in content"

68
es_ES Normal file
View File

@ -0,0 +1,68 @@
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Uso: _msg "" ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
_msg info "Uso: qsgen2 add \"Nombre del Sitio\" \"/ruta/al/proyecto\""
_msg sub "- Actualización Forzada: Generando Todo"
_msg debug "* ${0:t} no puede analizar este sitio. Saliendo. *"
_msg other "Por favor, instale Pandoc."
_msg other "https://github.com/jgm/pandoc/releases"
_msg debug "No se encontró ningún generador válido. ¿Estás seguro de haber seleccionado el generador correcto en 'config'?"
if (${globaldebug}); then _msg debug "Usando el motor ${generator} para archivos: ${file_ext}"; fi if ${debug}; then _msg
debug "_list_pages: No se encontraron páginas con extensión ${file_ext}."; fi if ${debug}; then _msg debug "_list_pages:
Agregando archivo al array: ${file}"; fi if ${debug}; then _msg debug "_list_blogs: No se encontraron archivos de blogs.";
fi if ${debug}; then _msg debug "_list_blogs: Agregando archivo al array: $file"; fi if (${debug}) _msg debug "_blog_cache:
VALOR HASH: ${blog_cache[${name}]}" if (${debug}) _msg debug "1. _blog_cache: ${blog_file}" if (${debug}) _msg debug "2.
_blog_cache: current_cache: ${current_hash}" if (${debug}) _msg debug "3. _blog_cache: new_cache_file: ${blog_file}$" if
(${debug}) _msg debug "4. _blog_cache: new_current_cache: ${current_hash}" if (${debug}) _msg debug "VALOR HASH DE PÁGINAS:
${pages_cache[${name}]}" if (${debug}) _msg debug "1. pages_cache: ${pages_cache[$file]}" if (${debug}) _msg debug "1.
_pages_cache: current_cache: ${current_hash}" if (${debug}) _msg debug "2. _pages_cache: pages_file: ${pages_cache[$file]}"
if (${debug}) _msg debug "2. _pages_cache: current_cache: ${current_hash}" if (${debug}); then _msg debug "_last_updated:
Estableciendo fecha y versión en el pie de página"; fi if (${debug}); then _msg debug "_last_updated: ${upd_msg}"; fi local
upd_msg="Última actualización ${today} por <a href="https://blog.kekepower.com/qsgen2.html">${QSGEN} ${VERSION}" -e
"s|#updated|${upd_msg}|") if (${debug}); then _msg debug "_f_last_updated: Estableciendo fecha y versión en el pie de página
del archivo ${1}"; fi if (${debug}); then _msg debug "_f_last_updated: ${upd_msg}"; fi local upd_msg="Última actualización
${today} por <a href="https://blog.kekepower.com/qsgen2.html">${QSGEN} ${VERSION}" -e "s|#updated|${upd_msg}|"
if (${debug}) _msg debug "_pages: Ejecutando función _pages_cache" _msg sub "* No tienes ninguna página " _msg main
"Generando Páginas" if (${debug}) _msg debug "_pages: pages_array no está vacío" if (${debug}) _msg debug "_pages:
Estableciendo plantilla de Páginas" _msg info "No se pudo encontrar la plantilla de Páginas: ${pages}" if (${debug}) _msg
debug "_pages: Leyendo plantilla de Páginas en pages_tpl" _msg std "- Generando Página: ${pages_in_array%.}.html" if
(${debug}) _msg debug "_pages: Cargando page_content una vez - ${pages_in_array}" if (${debug}) _msg debug "_pages: Buscando
page_title en page_content" if (${debug}) _msg debug "_pages: ${page_title}" if (${debug}) _msg debug "_pages: Eliminando
línea #title de page_content" if (${debug}) _msg debug "_pages: Ejecutando motor en ${pages_in_array}" if (${debug}) _msg
debug "_pages: Comprobando #link, #showimg y #ytvideo en page_content" if (${debug}) _msg debug "_pages: #link está
presente, ejecutar _link: page_content" if (${debug}) _msg debug "_pages: #showimg está presente, ejecutar _image:
page_content" if (${debug}) _msg debug "_pages: #ytvideo está presente, ejecutar _youtube: page_content" if (${debug}) _msg
debug "_pages: Reemplazando BODY con page_content en pages_tpl" if (${debug}) _msg debug "_pages: Reemplazando #pagetitle,
#tagline y #sitename en pages_tpl" if (${debug}) _msg debug "_pages: _last_updated en pages_tpl" if (${debug}) _msg debug
"_pages: Nombres de archivo en minúsculas, siempre" if (${debug}) _msg debug "_pages: Ejecutando _cleanup" # _msg std
"Escribiendo ${www_root}/${pages_title_lower%.}.html en el disco." if (${debug}) _msg sub "- Analizando ${pages_in_array}"
if (${debug}) _msg sub "- blog_in_index = ${blog_in_index}" if (${debug}) _msg sub "- Listando archivo temporal de blog:"
_msg std "Actualizando index.html con nuevas entradas de blog" if (${debug}) _msg sub "- Analizando ${pages_in_array}" if
(${debug}) _msg sub "- blog_in_index = ${blog_in_index}" if (${debug}) _msg sub "- Listando archivo temporal de blog:" _msg
sub "- No se encontraron Páginas nuevas o actualizadas" if (${debug}) _msg debug "_blogs: Ejecutando función _list_blogs"
_msg sub " No tienes ningún blog " _msg main "Generando Blogs" if (${debug}) _msg debug "_blogs: Ejecutando función
_blog_cache" _msg info "No se pudo encontrar la plantilla de tema para Blogs." if (${debug}) _msg debug "_blogs: Procesando
pre-datos para ${blog}" _msg debug "_blogs: Falta metadatos de FECHA en ${blog}." if (${debug}) _msg debug "_blogs:
Agregando datos para ${blog} al array para exportar" if (${debug}) _msg debug "_blogs: Procesando ${blog}" _msg std "-
Generando Blog: ${blog_index}.html" if (${debug}) _msg debug "_blogs: Procesando sustituciones en ${blog}" if (${debug})
_msg debug "_blogs: Ejecutando función $engine para ${blog}" if (${debug}) _msg debug "_blogs: Comprobando #link, #showimg y
#ytvideo en blog_content" if (${debug}) _msg debug "_blogs: #link está presente, ejecutar _link: blog_content" if (${debug})
_msg debug "_blogs: #showimg está presente, ejecutar _link: blog_content" if (${debug}) _msg debug "_blogs: #ytvideo está
presente, ejecutar _link: blog_content" if (${debug}) _msg debug "_blogs: Reemplazando tagline, sitename y pagetitle" if
(${debug}) _msg debug "_blogs: Creando directorio ${www_root}/${blog_dir}" if (${debug}) _msg debug "_blogs: Escribiendo
blog en disco: ${www_root}${blog_url}" _msg sub "- No se encontraron Blogs nuevos o actualizados" if (${debug}) _msg sub "
_blogs: Ejecutando _blog_idx_for_index" if (${debug}) _msg sub "* _blogs: Ejecutando _blog_index" _msg sub "- Poblando
${project_dir}/blog/index.tmp.html" if (${debug}) _msg debug "_blog_idx_for_index: Iniciando función" if (${debug}) _msg
debug "_blog_idx_for_index: BLOG_META_STR_ARRAY: ${BLOG_META_STR_ARRAY[@]}" if (${debug}) _msg debug "_blog_idx_for_index:
meta_str de BLOG_META_STR_ARRAY de _blogs" if (${debug}) _msg debug "_blog_idx_for_index: ${meta_str}" if (${debug}) _msg
debug "_blog_idx_for_index: Iterar sobre cada componente y extraer información" if (${debug}) _msg debug
"_blog_idx_for_index: Ejecutando ${engine} en contenido para capturar QStags en Ingress" if (${debug}) _msg debug
"_blog_idx_for_index

65
nb_NO Normal file
View File

@ -0,0 +1,65 @@
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Usage: _msg "" ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
_msg info "Bruk: qsgen2 add \"Nettstednavn\" \"/sti/til/prosjekt\""
_msg sub "- Tvungen oppdatering: Genererer alt"
_msg debug "* ${0:t} kan ikke analysere dette nettstedet. Avslutter. *"
_msg other "Vennligst installer Pandoc."
_msg other "https://github.com/jgm/pandoc/releases"
_msg debug "Ingen gyldig generator funnet. Er du sikker på at du har valgt riktig generator i 'config'?" if
(${globaldebug}); then _msg debug "Bruker ${generator}-motoren for filer: ${file_ext}"; fi if ${debug}; then _msg debug
"_list_pages: Ingen sider funnet med filtype ${file_ext}."; fi if ${debug}; then _msg debug "_list_pages: Legger til fil i
array: ${file}"; fi if ${debug}; then _msg debug "_list_blogs: Ingen bloggfiler funnet."; fi if ${debug}; then _msg debug
"_list_blogs: Legger til fil i array: $file"; fi if (${debug}) _msg debug "_blog_cache: HASH-VERDI: ${blog_cache[${name}]}"
if (${debug}) _msg debug "1. _blog_cache: ${blog_file}" if (${debug}) _msg debug "2. _blog_cache: current_cache:
${current_hash}" if (${debug}) _msg debug "3. _blog_cache: new_cache_file: ${blog_file}$" if (${debug}) _msg debug "4.
_blog_cache: new_current_cache: ${current_hash}" if (${debug}) _msg debug "SIDER HASH-VERDI: ${pages_cache[${name}]}" if
(${debug}) _msg debug "1. pages_cache: ${pages_cache[$file]}" if (${debug}) _msg debug "1. _pages_cache: current_cache:
${current_hash}" if (${debug}) _msg debug "2. _pages_cache: pages_file: ${pages_cache[$file]}" if (${debug}) _msg debug "2.
_pages_cache: current_cache: ${current_hash}" if (${debug}); then _msg debug "_last_updated: Setter dato og versjon i
bunnteksten"; fi if (${debug}); then _msg debug "_last_updated: ${upd_msg}"; fi local upd_msg="Sist oppdatert ${today} av <a
href="https://blog.kekepower.com/qsgen2.html">${QSGEN} ${VERSION}" -e "s|#updated|${upd_msg}|") if (${debug}); then _msg
debug "_f_last_updated: Setter dato og versjon i bunnteksten til filen ${1}"; fi if (${debug}); then _msg debug
"_f_last_updated: ${upd_msg}"; fi local upd_msg="Sist oppdatert ${today} av <a
href="https://blog.kekepower.com/qsgen2.html">${QSGEN} ${VERSION}" -e "s|#updated|${upd_msg}|"
if (${debug}) _msg debug "_pages: Kjører funksjonen _pages_cache" _msg sub "* Du har ingen sider " _msg main "Genererer
Sider" if (${debug}) _msg debug "_pages: pages_array er ikke tom" if (${debug}) _msg debug "_pages: Setter Sider-malen" _msg
info "Kan ikke finne Sider-malen: ${pages}" if (${debug}) _msg debug "_pages: Leser inn Sider-malen i pages_tpl" _msg std "-
Genererer Side: ${pages_in_array%.}.html" if (${debug}) _msg debug "_pages: Laster inn sideinnhold én gang -
${pages_in_array}" if (${debug}) _msg debug "_pages: Grep etter side_tittel" if (${debug}) _msg debug "_pages:
${page_title}" if (${debug}) _msg debug "_pages: Fjerner #tittel-linjen fra sideinnholdet" if (${debug}) _msg debug "_pages:
Kjører motoren på ${pages_in_array}" if (${debug}) _msg debug "_pages: Sjekker etter #link, #showimg og #ytvideo i
sideinnholdet" if (${debug}) _msg debug "_pages: #link er tilstede, kjør _link: sideinnholdet" if (${debug}) _msg debug
"_pages: #showimg er tilstede, kjør _image: sideinnholdet" if (${debug}) _msg debug "_pages: #ytvideo er tilstede, kjør
_youtube: sideinnholdet" if (${debug}) _msg debug "_pages: Erstatter BODY med sideinnholdet i pages_tpl" if (${debug}) _msg
debug "_pages: Erstatter #sidetittel, #tagline og #nettstednavn i pages_tpl" if (${debug}) _msg debug "_pages: _last_updated
i pages_tpl" if (${debug}) _msg debug "_pages: Filnavn i små bokstaver, alltid" if (${debug}) _msg debug "_pages: Kjører
_cleanup" # _msg std "Skriver ${www_root}/${pages_title_lower%.}.html til disk." if (${debug}) _msg sub "- Analyserer
${pages_in_array}" if (${debug}) _msg sub "- blog_in_index = ${blog_in_index}" if (${debug}) _msg sub "- List opp
midlertidig bloggfil:" _msg std "Oppdaterer index.html med nye blogginnlegg" if (${debug}) _msg sub "- Analyserer
${pages_in_array}" if (${debug}) _msg sub "- blog_in_index = ${blog_in_index}" if (${debug}) _msg sub "- List opp
midlertidig bloggfil:" _msg sub "- Ingen nye eller oppdaterte Sider funnet" if (${debug}) _msg debug "_blogs: Kjører
funksjonen _list_blogs" _msg sub " Du har ingen blogger " _msg main "Genererer Blogger" if (${debug}) _msg debug "_blogs:
Kjører funksjonen _blog_cache" _msg info "Kan ikke finne temamalen for Blogger." if (${debug}) _msg debug "_blogs: Behandler
pre-data for ${blog}" _msg debug "_blogs: DATO-metadata mangler i ${blog}." if (${debug}) _msg debug "_blogs: Legger til
data for ${blog} i array for eksport" if (${debug}) _msg debug "_blogs: Behandler ${blog}" _msg std "- Genererer Blogg:
${blog_index}.html" if (${debug}) _msg debug "_blogs: Behandler erstatninger i ${blog}" if (${debug}) _msg debug "_blogs:
Kjører funksjonen $engine for ${blog}" if (${debug}) _msg debug "_blogs: Sjekker etter #link, #showimg og #ytvideo i
blogginnholdet" if (${debug}) _msg debug "_blogs: #link er tilstede, kjør _link: blogginnholdet" if (${debug}) _msg debug
"_blogs: #showimg er tilstede, kjør _link: blogginnholdet" if (${debug}) _msg debug "_blogs: #ytvideo er tilstede, kjør
_link: blogginnholdet" if (${debug}) _msg debug "_blogs: Erstatter tagline, nettstednavn og sidetittel" if (${debug}) _msg
debug "_blogs: Oppretter katalogen ${www_root}/${blog_dir}" if (${debug}) _msg debug "_blogs: Skriver blogg til disk:
${www_root}${blog_url}" _msg sub "- Ingen nye eller oppdaterte Blogger funnet" if (${debug}) _msg sub " _blogs: Kjører
_blog_idx_for_index" if (${debug}) _msg sub "* _blogs: Kjører _blog_index" _msg sub "- Fyller
${project_dir}/blog/index.tmp.html" if (${debug}) _msg debug "_blog_idx_for_index: Starter funksjonen" if (${debug}) _msg
debug "_blog_idx_for_index: BLOG_META_STR_ARRAY: ${BLOG_META_STR_ARRAY[@]}" if (${debug}) _msg debug "_blog_idx_for_index:
meta_str fra BLOG_META_STR_ARRAY fra _blogs" if (${debug}) _msg debug "_blog_idx_for_index: ${meta_str}" if (${debug}) _msg
debug "_blog_idx_for_index: Gå gjenn

46
qsgen2
View File

@ -10,7 +10,7 @@
# https://github.com/kekePower/qsgen2/ # https://github.com/kekePower/qsgen2/
# #
VERSION="0.3.4" # Thu-2024-02-08 VERSION="0.3.5" # Thu-2024-02-08
QSGEN="Quick Site Generator 2" QSGEN="Quick Site Generator 2"
# Set to true or false # Set to true or false
@ -507,8 +507,24 @@ function _pages() {
local page_content="$(<${pages_in_array})" local page_content="$(<${pages_in_array})"
# Grab the title from the Page # Grab the title from the Page
if (${debug}) _msg debug "_pages: Grepping for page_title" if (${debug}) _msg debug "_pages: Finding page_title"
local page_title=$( echo ${page_content} | head -2 | grep \#title | cut -d= -f2 ) if [[ ${generator} == "native" ]]; then
# Use Zsh built in functions to find page_title
[[ "${page_content}" =~ ^#title=(.*) ]] && local page_title=${match[1]}
#local page_title=$( echo ${page_content} | head -2 | grep \#title | cut -d= -f2 )
elif [[ ${generator} == "markdown" ]]; then
while IFS= read -r line
do
# Check if the line starts with '#' and capture the line
if [[ "$line" == \#* ]]; then
# Remove all leading '#' characters and the first space (if present)
local page_title="${line#\#}" # Remove the first '#' character
page_title="${page_title#\#}" # Remove the second '#' character if present
page_title="${page_title#"${page_title%%[![:space:]]*}"}" # Trim leading whitespace
break # Exit the loop after finding the first heading
fi
done < ${page_content}
fi
if (${debug}) _msg debug "_pages: ${page_title}" if (${debug}) _msg debug "_pages: ${page_title}"
# Remove the #title line from the buffer. No longer needed. # Remove the #title line from the buffer. No longer needed.
@ -641,16 +657,36 @@ function _blogs() {
local sdate btitle ingress body blog_index blog_dir blog_url local sdate btitle ingress body blog_index blog_dir blog_url
# Check for the DATE line # Check for the DATE line
if ! echo "$content" | grep -q "^DATE "; then if [[ ! "${content}" =~ ^DATE\ ]]; then
_msg debug "_blogs: DATE metadata missing in ${blog}." _msg debug "_blogs: DATE metadata missing in ${blog}."
continue # Skip this file and move to the next continue # Skip this file and move to the next
fi fi
# Check for the BLOG_TITLE line
if [[ ! "${content}" =~ ^BLOG_TITLE\ ]]; then
_msg debug "_blogs: BLOG_TITLE metadata missing in ${blog}."
continue # Skip this file and move to the next
fi
# Extract blog information # Extract blog information
sed -i "s/GETDATE/${blogdate}/" ${blog} sed -i "s/GETDATE/${blogdate}/" ${blog}
# Array sdate = Name day=1, Year=2, Month=3, Number day=4 # Array sdate = Name day=1, Year=2, Month=3, Number day=4
sdate=( $( echo ${content} | grep DATE | sed "s|DATE\ ||" | sed "s|\-|\ |g" ) ) sdate=( $( echo ${content} | grep DATE | sed "s|DATE\ ||" | sed "s|\-|\ |g" ) )
btitle=$( echo ${content} | grep BLOG_TITLE | cut -d' ' -f2- ) if [[ ${generator} == "native" ]]; then
if [[ "${content}" =~ "^BLOG_TITLE (.*)$" ]] && btitle=${match[1]}
#btitle=$( echo ${content} | grep BLOG_TITLE | cut -d' ' -f2- )
elif [[ ${generator} == "markdown" ]]; then
while IFS= read -r line
do
# Check if the line starts with '#' and capture the line
if [[ "$line" == \#* ]]; then
# Remove all leading '#' characters and the first space (if present)
btitle="${line#\#}" # Remove the first '#' character
btitle="${btitle#\#}" # Remove the second '#' character if present
btitle="${btitle#"${btitle%%[![:space:]]*}"}" # Trim leading whitespace
break # Exit the loop after finding the first heading
fi
done < ${content}
fi
ingress=$( echo ${content} | sed "s/'/\\\'/g" | xargs | grep -Po "#INGRESS_START\K(.*?)#INGRESS_STOP" | sed "s|\ \#INGRESS_STOP||" | sed "s|^\ ||" ) ingress=$( echo ${content} | sed "s/'/\\\'/g" | xargs | grep -Po "#INGRESS_START\K(.*?)#INGRESS_STOP" | sed "s|\ \#INGRESS_STOP||" | sed "s|^\ ||" )
body=$( echo ${content} | sed "s/'/\\\'/g" | xargs | grep -Po "#BODY_START\K(.*?)#BODY_STOP" | sed "s|\ \#BODY_STOP||" | sed "s|^\ ||" ) body=$( echo ${content} | sed "s/'/\\\'/g" | xargs | grep -Po "#BODY_START\K(.*?)#BODY_STOP" | sed "s|\ \#BODY_STOP||" | sed "s|^\ ||" )