A first try to get the _pages function working
This commit is contained in:
parent
f155a67696
commit
a8648b126e
110
qsgen2
110
qsgen2
@ -116,6 +116,13 @@ if (${debug}); then
|
|||||||
echo "${yellow} - generator=${generator}${end}"
|
echo "${yellow} - generator=${generator}${end}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Let's check if qsgen2 can generate this site by checking if 'generator' is available
|
||||||
|
if [[ ! ${generator} ]]; then
|
||||||
|
echo "${0:t} cannot parse this site. Exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# We define the variable 'engine' based on what's in the 'config' file.
|
||||||
if [[ ${generator} == "native" ]]; then
|
if [[ ${generator} == "native" ]]; then
|
||||||
# Usage: ${engine} ${1} - Where 1 is the file you want to convert
|
# Usage: ${engine} ${1} - Where 1 is the file you want to convert
|
||||||
engine=_html
|
engine=_html
|
||||||
@ -124,8 +131,15 @@ elif [[ ${generator} == "markdown" ]]; then
|
|||||||
echo "Please install the 'discount' package to use Markdown."
|
echo "Please install the 'discount' package to use Markdown."
|
||||||
exit
|
exit
|
||||||
else
|
else
|
||||||
# Usage: ${engine} ${1} ${2} - Where 1 is the input file and 2 is the html www_root file and location
|
# Let's make sure that the Markdown executable gets all its variables: 1 and 2
|
||||||
engine=$( /usr/bin/markdown -o ${2} ${1} )
|
if [[ ! ${2} ]] || [[ ${2} == "" ]]; then
|
||||||
|
echo "Engine: To use Markdown, please provide a second variable, the output file."
|
||||||
|
echo "Engine: Example: engine file.tpl www_root/file.html"
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
# Usage: ${engine} ${1} - Where 1 is the file you want parsed
|
||||||
|
engine=$( /usr/bin/markdown ${1} -d )
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if (${debug}) echo "${red}Using the ${generator} engine${end}"
|
if (${debug}) echo "${red}Using the ${generator} engine${end}"
|
||||||
@ -204,6 +218,7 @@ done
|
|||||||
|
|
||||||
|
|
||||||
# PAGES CACHE
|
# PAGES CACHE
|
||||||
|
# Returns the array pages_array()
|
||||||
function _pages_cache() {
|
function _pages_cache() {
|
||||||
local debug=false
|
local debug=false
|
||||||
# Create an associative array for the pages cache
|
# Create an associative array for the pages cache
|
||||||
@ -218,7 +233,7 @@ if [[ -f $pages_cache_file ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Initialize the array for storing pages files to process
|
# Initialize the array for storing pages files to process
|
||||||
tpl_array=()
|
pages_array=()
|
||||||
|
|
||||||
# Process pages files
|
# Process pages files
|
||||||
for file in $(ls -1bt *tpl); do
|
for file in $(ls -1bt *tpl); do
|
||||||
@ -233,7 +248,7 @@ for file in $(ls -1bt *tpl); do
|
|||||||
if (${debug}) echo "${red}2. pages_file: ${pages_cache[$file]}${end}"
|
if (${debug}) echo "${red}2. pages_file: ${pages_cache[$file]}${end}"
|
||||||
if (${debug}) echo "${red}2. current_cache: ${current_hash}${end}"
|
if (${debug}) echo "${red}2. current_cache: ${current_hash}${end}"
|
||||||
# Pages file is new or has changed; add it to the processing array
|
# Pages file is new or has changed; add it to the processing array
|
||||||
tpl_array+=("$file")
|
pages_array+=("$file")
|
||||||
|
|
||||||
# Update the pages cache with the new hash
|
# Update the pages cache with the new hash
|
||||||
pages_cache[$file]=$current_hash
|
pages_cache[$file]=$current_hash
|
||||||
@ -251,16 +266,99 @@ function _last_updated() {
|
|||||||
tee < ${1} | sed -e "s|#updated|${TODAY}|" | sed -e "s|\#version|${QSGEN} ${VERSION}|" > ${1}
|
tee < ${1} | sed -e "s|#updated|${TODAY}|" | sed -e "s|\#version|${QSGEN} ${VERSION}|" > ${1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _file_to_lower() {
|
||||||
|
|
||||||
|
local filename=${1}
|
||||||
|
|
||||||
|
# Replace spaces with dashes
|
||||||
|
filename="${filename// /-}"
|
||||||
|
|
||||||
|
# Convert to lowercase and remove invalid characters
|
||||||
|
filename=$(echo "${filename}" | sed -e 's/^[^a-zA-Z0-9_.]+//g' -e 's/[^a-zA-Z0-9_-]+/-/g')
|
||||||
|
|
||||||
|
return ${filename}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function _pages() {
|
function _pages() {
|
||||||
# This function generates all the pages
|
# This function generates all the new and updated Pages
|
||||||
|
|
||||||
local debug=false
|
local debug=false
|
||||||
|
|
||||||
local pages=${project_dir}/templates/${theme}/pages.tpl
|
local pages=${project_dir}/templates/${theme}/pages.tpl
|
||||||
|
|
||||||
|
# Let's check if we can access the pages.tpl file.
|
||||||
|
# It not, exit script.
|
||||||
if [[ ! -f ${pages} ]]; then
|
if [[ ! -f ${pages} ]]; then
|
||||||
echo "Unable to find the Pages template: ${pages}"
|
echo "Unable to find the Pages template: ${pages}"
|
||||||
exit
|
exit
|
||||||
|
else
|
||||||
|
# Read template once
|
||||||
|
pages_tpl="$(<${pages})"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Load the cache for Pages
|
||||||
|
_pages_cache
|
||||||
|
|
||||||
|
if (( ${#pages_array[@]} > 0 )); then
|
||||||
|
# If pages_array is not empty, we do work
|
||||||
|
|
||||||
|
local out="${www_root}"
|
||||||
|
|
||||||
|
for pages_in_array in ${pages_array[@]}
|
||||||
|
do
|
||||||
|
echo "${green}Generating Page: ${pages_in_array}${end}"
|
||||||
|
# Read the file once
|
||||||
|
local page_content="$(<${pages_in_array})"
|
||||||
|
|
||||||
|
# Grab the title from the Page
|
||||||
|
page_title=$( echo ${page_content} | head -2 | grep '#title' | cut -d= -f2 )
|
||||||
|
|
||||||
|
# Remove the #title line from the buffer. No longer needed.
|
||||||
|
page_content=$( echo ${page_content} | grep -v #title )
|
||||||
|
|
||||||
|
# HTML'ify the page content
|
||||||
|
page_content=$( ${engine} ${page_content} )
|
||||||
|
|
||||||
|
# Look for links, images and videos and convert them if present.
|
||||||
|
if [[ $( grep \#link ${page_content} ) ]]; then
|
||||||
|
echo "If #link is present, run _link: ${page_content}"
|
||||||
|
_link ${page_content}
|
||||||
|
elif [[ $( grep \#showimg ${page_content} ) ]]; then
|
||||||
|
echo "If #showimg is present, run _image: ${page_content}"
|
||||||
|
_image ${page_content}
|
||||||
|
elif [[ $( grep \#ytvideo ${page_content} ) ]]; then
|
||||||
|
echo "If #ytvideo is present, run _youtube: ${page_content}"
|
||||||
|
_youtube ${page_content}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Insert page_content into pages_tpl by replacing the BODY tag present there
|
||||||
|
page_tpl=$( echo ${page_tpl} | sed -e "s|BODY|${page_content}|" )
|
||||||
|
|
||||||
|
# Replace every #pagetitle in pages_tpl
|
||||||
|
pages_tpl=$( echo ${pages_tpl} | sed -e "s|#pagetitle|${page_title}|g" )
|
||||||
|
|
||||||
|
# Replace every #tagline in pages_tpl
|
||||||
|
pages_tpl=$( echo ${pages_tpl} | sed -e "s|#tagline|${site_tagline}|g" )
|
||||||
|
|
||||||
|
# Replace #updated with today's date
|
||||||
|
pages_tpl=$( _last_updated ${pages_tpl} )
|
||||||
|
|
||||||
|
# Replace #version with the Name and Version of the script
|
||||||
|
pages_tpl=$( echo ${pages_tpl} | sed -e "s|#version|${QSGEN} ${VERSION}|" )
|
||||||
|
|
||||||
|
# Run a cleanup if in case something was left out
|
||||||
|
_cleanup ${pages_tpl}
|
||||||
|
|
||||||
|
# Write pages_tpl to disk
|
||||||
|
echo "Writing ${pages_in_array} to disk."
|
||||||
|
|
||||||
|
# Always use lowercase for file names
|
||||||
|
pages_title_lower=$( _file_to_lower "${page_title}" )
|
||||||
|
echo "${pages_tpl}" > ${www_root}/${pages_title_lower%.}.html
|
||||||
|
done
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -290,7 +388,7 @@ function _blogs() {
|
|||||||
|
|
||||||
local sdate btitle ingress body blog_index blog_dir blog_url
|
local sdate btitle ingress body blog_index blog_dir blog_url
|
||||||
|
|
||||||
echo "_blogs: _blog_list_for_index: Just before the for loop: make_blog_array"
|
if (${debug}) echo "_blogs: _blog_list_for_index: Just before the for loop: make_blog_array"
|
||||||
for blog in ${make_blog_array[@]}
|
for blog in ${make_blog_array[@]}
|
||||||
do
|
do
|
||||||
if (${debug}) echo "0001: ${red}_blogs: _blog_list_for_index: Processing ${blog}${end}"
|
if (${debug}) echo "0001: ${red}_blogs: _blog_list_for_index: Processing ${blog}${end}"
|
||||||
|
Loading…
Reference in New Issue
Block a user