diff --git a/.github/scripts/convertH1toH2.sh b/.github/scripts/convertH1toH2.sh deleted file mode 100755 index bf26d9f..0000000 --- a/.github/scripts/convertH1toH2.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -basePath="./KnowledgeBase/" - -for path in $(find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print); do - # Replace all instances of # with ## - this converts all H1 to H2 - sed -i 's/\(^#\)\(\s\)/\#\#\2/g' ${path} -done \ No newline at end of file diff --git a/.github/scripts/addFrontMatter.sh b/.github/scripts/debug/addFrontMatter.sh similarity index 50% rename from .github/scripts/addFrontMatter.sh rename to .github/scripts/debug/addFrontMatter.sh index 03c87ec..4d0543c 100755 --- a/.github/scripts/addFrontMatter.sh +++ b/.github/scripts/debug/addFrontMatter.sh @@ -1,24 +1,24 @@ -#!/bin/sh +#!/bin/bash basePath="./KnowledgeBase/" startEnd="---" -#tab=" " + +echo "[DEBUG] Adding front matter to all markdown files in ${basePath}..." find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print | while IFS= read -r path; do + echo "[DEBUG] Adding front matter to ${path}..." subject=$(dirname "${path}") # generate a category from the parent directory of the file - subjectLower=$(dirname "${path}" | awk -F "/" '{print tolower($NF)}') # generate a category from the parent directory of the file - in lowercase title=$(basename -s .md "${path}") # generate a title from the file name titleLower=$(echo "${title}" | awk '{print tolower($0)}') # set the title to lowercase titleSpaces=$(echo "${title}" | tr "-" " " ) # replace hyphens with spaces excerpt=$(sed -n 3p "${path}") # get the first non-title line of the file - # Remove special chracters from excerpt - excerpt=$(echo "${excerpt}" | sed -e 's/[^a-zA-Z0-9 ]//g') + excerpt=$(echo "${excerpt}" | sed -e 's/[^a-zA-Z0-9 ]//g') # Remove special chracters from excerpt frontMatter="${startEnd}\npermalink: /knowledge/${titleLower}/\nsubject: ${subject}\ntitle: ${titleSpaces}\nexcerpt: "${excerpt}"\n${startEnd}" # build Liquid Front Matter - builds multiline string - # Removed the subject from the front matter as the path on my website does not include the subject and all posts as from /knowledge - #frontMatter="${startEnd}\npermalink: /knowledge/${subjectLower}/${titleLower}/\nsubject: ${subject}\ntitle: ${titleSpaces}\nexcerpt: "${excerpt}"\n${startEnd}" # build Liquid Front Matter - builds multiline string + echo "[DEBUG] Front matter: ${frontMatter}" sed -i "1i ${frontMatter}" "${path}" # prepend the front matter to the head of the file - # Add new line after end of file - echo "" >> "${path}" - # Append breadcrumbs include to the end of the file on a new line and adding a new line to the end of the file - echo "{% include breadcrumbs2.html %}" >> "${path}" + echo "" >> "${path}" # Add new line after end of file + echo "{% include breadcrumbs2.html %}" >> "${path}" # Append breadcrumbs include to the end of the file on a new line and adding a new line to the end of the file + echo "[DEBUG] Front matter added to ${path}." done + +echo "[DEBUG] Front matter added to all markdown files in ${basePath}." diff --git a/.github/scripts/debug/convertH1toH2.sh b/.github/scripts/debug/convertH1toH2.sh new file mode 100755 index 0000000..59a41f8 --- /dev/null +++ b/.github/scripts/debug/convertH1toH2.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +basePath="./KnowledgeBase/" + +echo "[DEBUG] Converting all H1 to H2 in all markdown files in ${basePath}..." + +for path in $(find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print); do + echo "[DEBUG] Converting all H1 to H2 in ${path}..." + # Replace all instances of # with ## - this converts all H1 to H2 + sed -i 's/\(^#\)\(\s\)/\#\#\2/g' "${path}" + echo "[DEBUG] All H1 converted to H2 in ${path}." +done + +echo "[DEBUG] All H1 converted to H2 in all markdown files in ${basePath}." \ No newline at end of file diff --git a/.github/scripts/debug/printFileContents.sh b/.github/scripts/debug/printFileContents.sh new file mode 100755 index 0000000..093c504 --- /dev/null +++ b/.github/scripts/debug/printFileContents.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Directory containing the markdown files +dir="./KnowledgeBase/" + +echo "[DEBUG] Generating output for all markdown files in $dir" + +# Find all markdown files in the directory and its subdirectories +find $dir -name "*.md" | while read -r file; do + echo "[DEBUG] Found markdown file: $file" + echo "Printing contents of $file" + cat "$file" +done + +echo "[DEBUG] Done generating output for all markdown files in $dir" \ No newline at end of file diff --git a/.github/scripts/debug/updateLinks.sh b/.github/scripts/debug/updateLinks.sh new file mode 100755 index 0000000..e6349b4 --- /dev/null +++ b/.github/scripts/debug/updateLinks.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +basePath="./KnowledgeBase/" + +echo "[DEBUG] Converting all links to lowercase permalinks in all markdown files in ${basePath}..." + +find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print | while IFS= read -r path; do + echo "[DEBUG] Converting all links to lowercase permalinks in ${path}..." + sed -i`` 's/\(.*\).md/\L\1/g' "${path}" # convert links to other markdown files to lowercase permalinks with .md extension removed + echo "[DEBUG] All links converted to lowercase permalinks in ${path}." +done + +echo "[DEBUG] All links converted to lowercase permalinks in all markdown files in ${basePath}." diff --git a/.github/scripts/prod/addFrontMatter.sh b/.github/scripts/prod/addFrontMatter.sh new file mode 100755 index 0000000..1ef3ebc --- /dev/null +++ b/.github/scripts/prod/addFrontMatter.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +basePath="./KnowledgeBase/" +startEnd="---" + +echo "[INFO] Adding front matter to all markdown files in ${basePath}..." + +find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print | while IFS= read -r path; do + echo "[INFO] Adding front matter to ${path}..." + subject=$(dirname "${path}") # generate a category from the parent directory of the file + title=$(basename -s .md "${path}") # generate a title from the file name + titleLower=$(echo "${title}" | awk '{print tolower($0)}') # set the title to lowercase + titleSpaces=$(echo "${title}" | tr "-" " " ) # replace hyphens with spaces + excerpt=$(sed -n 3p "${path}") # get the first non-title line of the file + excerpt=$(echo "${excerpt}" | sed -e 's/[^a-zA-Z0-9 ]//g') # Remove special chracters from excerpt + frontMatter="${startEnd}\npermalink: /knowledge/${titleLower}/\nsubject: ${subject}\ntitle: ${titleSpaces}\nexcerpt: "${excerpt}"\n${startEnd}" # build Liquid Front Matter - builds multiline string + sed -i "1i ${frontMatter}" "${path}" # prepend the front matter to the head of the file + echo "" >> "${path}" # Add new line after end of file + echo "{% include breadcrumbs2.html %}" >> "${path}" # Append breadcrumbs include to the end of the file on a new line and adding a new line to the end of the file + echo "[INFO] Front matter added to ${path}." +done + +echo "[INFO] Front matter added to all markdown files in ${basePath}." diff --git a/.github/scripts/prod/convertH1toH2.sh b/.github/scripts/prod/convertH1toH2.sh new file mode 100755 index 0000000..f3cf445 --- /dev/null +++ b/.github/scripts/prod/convertH1toH2.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +basePath="./KnowledgeBase/" + +echo "[INFO] Converting all H1 to H2 in all markdown files in ${basePath}..." + +for path in $(find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print); do + echo "[INFO] Converting all H1 to H2 in ${path}..." + sed -i 's/\(^#\)\(\s\)/\#\#\2/g' "${path}" # Replace all instances of # with ## - this converts all H1 to H2 + echo "[INFO] All H1 converted to H2 in ${path}." +done + +echo "[INFO] All H1 converted to H2 in all markdown files in ${basePath}." \ No newline at end of file diff --git a/.github/scripts/prod/printFileContents.sh b/.github/scripts/prod/printFileContents.sh new file mode 100755 index 0000000..10aaec2 --- /dev/null +++ b/.github/scripts/prod/printFileContents.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Directory containing the markdown files +dir="./KnowledgeBase/" + +echo "[INFO] Generating output for all markdown files in $dir" + +# Find all markdown files in the directory and its subdirectories +find $dir -name "*.md" | while read -r file; do + echo "[INFO] Found markdown file: $file" + echo "Printing contents of $file" + cat "$file" +done + +echo "[INFO] Done generating output for all markdown files in $dir" \ No newline at end of file diff --git a/.github/scripts/prod/updateLinks.sh b/.github/scripts/prod/updateLinks.sh new file mode 100755 index 0000000..ca96217 --- /dev/null +++ b/.github/scripts/prod/updateLinks.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +basePath="./KnowledgeBase/" + +echo "[INFO] Converting all links to lowercase permalinks in all markdown files in ${basePath}..." + +find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print | while IFS= read -r path; do + echo "[INFO] Converting all links to lowercase permalinks in ${path}..." + sed -i`` 's/\(.*\).md/\L\1/g' ${path} # convert links to other markdown files to lowercase permalinks with .md extension removed + echo "[INFO] All links converted to lowercase permalinks in ${path}." +done + +echo "[INFO] All links converted to lowercase permalinks in all markdown files in ${basePath}." diff --git a/.github/scripts/updateLinks.sh b/.github/scripts/updateLinks.sh deleted file mode 100755 index 41fa86d..0000000 --- a/.github/scripts/updateLinks.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -basePath="./KnowledgeBase/" - -for path in $(find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print); do - # sed -i 's/\((\)\.\.\/\(.*\)/\1\.\.\/\.\.\/\2/g' ${path} # replace all instances of ../ with ../../ - sed -i`` 's/\(.*\).md/\L\1/g' ${path} # convert links to other markdown files to lowercase permalinks with .md extension removed -done diff --git a/.github/workflows/Copy-To-GrahamWattsWeb.yml b/.github/workflows/Copy-To-GrahamWattsWeb.yml index 3370166..2169056 100644 --- a/.github/workflows/Copy-To-GrahamWattsWeb.yml +++ b/.github/workflows/Copy-To-GrahamWattsWeb.yml @@ -19,11 +19,11 @@ jobs: with: submodules: true - name: Add Front Matter - run: .github/scripts/addFrontMatter.sh + run: .github/scripts/prod/addFrontMatter.sh - name: Update Links - run: .github/scripts/updateLinks.sh + run: .github/scripts/prod/updateLinks.sh - name: Convert H1 to H2 - run: .github/scripts/convertH1toH2.sh + run: .github/scripts/prod/convertH1toH2.sh - name: Copy files to GrahamWattsWeb uses: nkoppel/push-files-to-another-repository@v1.1.2 env: diff --git a/.github/workflows/VerifyOutput.yml b/.github/workflows/VerifyOutput.yml new file mode 100644 index 0000000..f4bae2c --- /dev/null +++ b/.github/workflows/VerifyOutput.yml @@ -0,0 +1,25 @@ +name: Verify Output + +on: + push: + branches: + - '*' + - '!main' + workflow_dispatch: + +jobs: + copy-to-grahamwattsweb: + runs-on: ubuntu-latest + steps: + - name: checkout KnowledgeBase + uses: actions/checkout@v4 + with: + submodules: true + - name: Add Front Matter + run: .github/scripts/debug/addFrontMatter.sh + - name: Update Links + run: .github/scripts/debug/updateLinks.sh + - name: Convert H1 to H2 + run: .github/scripts/debug/convertH1toH2.sh + - name: "[DEBUG] Show file contents" + run: .github/scripts/debug/printFileContents.sh