Skip to content

Commit

Permalink
Adding logging, disabled copy
Browse files Browse the repository at this point in the history
  • Loading branch information
GingerGraham committed Apr 3, 2024
1 parent 29f559e commit b941770
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
9 changes: 8 additions & 1 deletion .github/scripts/addFrontMatter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@ 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
# 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')
frontMatter="${startEnd}\npermalink: /knowledge/${titleLower}/\nsubject: ${subject}\ntitle: ${titleSpaces}\nexcerpt: "${excerpt}"\n${startEnd}" # build Liquid Front Matter - builds multiline string
echo "[DEBUG] Front matter: ${frontMatter}"
# 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
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 "[DEBUG] Front matter added to ${path}."
done

echo "[DEBUG] Front matter added to all markdown files in ${basePath}."
18 changes: 15 additions & 3 deletions .github/scripts/convertH1toH2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

basePath="./KnowledgeBase/"

for path in $(find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print); do
echo "[DEBUG] Converting all H1 to H2 in all markdown files in ${basePath}..."

find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -exec sh -c '
path="$1"
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}."
' sh {} \;
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}
done
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/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"
8 changes: 7 additions & 1 deletion .github/scripts/updateLinks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

basePath="./KnowledgeBase/"

for path in $(find ${basePath} -type f \( -iname "*.md" ! -iname "*index*" ! -iname "*readme*" \) -print); do
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/\((\)\.\.\/\(.*\)/\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
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}."
28 changes: 15 additions & 13 deletions .github/workflows/Copy-To-GrahamWattsWeb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ jobs:
run: .github/scripts/updateLinks.sh
- name: Convert H1 to H2
run: .github/scripts/convertH1toH2.sh
- name: Copy files to GrahamWattsWeb
uses: nkoppel/[email protected]
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source-files: 'KnowledgeBase/*'
destination-username: 'gingergraham'
destination-repository: 'GrahamWattsWeb'
destination-branch: 'main'
destination-directory: 'src/_knowledge/'
commit-email: '[email protected]'
commit-username: 'Graham Watts'
commit-message: 'Copy from KnowledgeBase'
- name: [DEBUG] Show file contents
run: github/scripts/printFileContents.sh
# - name: Copy files to GrahamWattsWeb
# uses: nkoppel/[email protected]
# env:
# API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
# with:
# source-files: 'KnowledgeBase/*'
# destination-username: 'gingergraham'
# destination-repository: 'GrahamWattsWeb'
# destination-branch: 'main'
# destination-directory: 'src/_knowledge/'
# commit-email: '[email protected]'
# commit-username: 'Graham Watts'
# commit-message: 'Copy from KnowledgeBase'

# source-files (argument)
# The files/directories to copy to the destination repository. Can have multiple space-separated filenames and globbing.
Expand Down

0 comments on commit b941770

Please sign in to comment.