Refactor _pages function in qsgen2 script to use a while loop to find the page_title. This change allows the function to work with both native and markdown generators.

This commit is contained in:
Stig-Ørjan Smelror 2024-02-12 20:29:04 +01:00
parent bdc218a0a0
commit 67136642e5

9
qsgen2
View File

@ -510,11 +510,14 @@ function _pages() {
# Grab the title from the Page # Grab the title from the Page
if (${debug}) _msg debug "_pages: Finding page_title" if (${debug}) _msg debug "_pages: Finding page_title"
if [[ ${generator} == "native" ]]; then if [[ ${generator} == "native" ]]; then
# Use Zsh built in functions to find page_title while read -r line
if [[ "${page_content}" =~ ^#title=(.*) ]]; then do
local page_title=$match[1] if [[ "$line" =~ ^#title=(.*) ]]; then
local page_title=${match[1]}
break
#local page_title=$( echo ${page_content} | head -2 | grep \#title | cut -d= -f2 ) #local page_title=$( echo ${page_content} | head -2 | grep \#title | cut -d= -f2 )
fi fi
done <<< "$page_content"
elif [[ ${generator} == "markdown" ]]; then elif [[ ${generator} == "markdown" ]]; then
while IFS= read -r line while IFS= read -r line
do do