Skip to content

Commit

Permalink
Feature/debugging copy files adding logging (#4)
Browse files Browse the repository at this point in the history
* Adding logging, disabled copy

* Modified to run on push to all branches for debugging

* Fixing pipeline file bug

* Fixing an error due to shell types in convert script

* Reverting changes to path loop

* Script path for printing file contents was wrong

* Updating script permissions

* Updated pipelines for main and other branches
  • Loading branch information
GingerGraham authored Apr 3, 2024
1 parent 29f559e commit a6395b7
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 30 deletions.
8 changes: 0 additions & 8 deletions .github/scripts/convertH1toH2.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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}."
14 changes: 14 additions & 0 deletions .github/scripts/debug/convertH1toH2.sh
Original file line number Diff line number Diff line change
@@ -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}."
15 changes: 15 additions & 0 deletions .github/scripts/debug/printFileContents.sh
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 13 additions & 0 deletions .github/scripts/debug/updateLinks.sh
Original file line number Diff line number Diff line change
@@ -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}."
23 changes: 23 additions & 0 deletions .github/scripts/prod/addFrontMatter.sh
Original file line number Diff line number Diff line change
@@ -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}."
13 changes: 13 additions & 0 deletions .github/scripts/prod/convertH1toH2.sh
Original file line number Diff line number Diff line change
@@ -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}."
15 changes: 15 additions & 0 deletions .github/scripts/prod/printFileContents.sh
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 13 additions & 0 deletions .github/scripts/prod/updateLinks.sh
Original file line number Diff line number Diff line change
@@ -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}."
8 changes: 0 additions & 8 deletions .github/scripts/updateLinks.sh

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/Copy-To-GrahamWattsWeb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
env:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/VerifyOutput.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a6395b7

Please sign in to comment.