Skip to content

Commit

Permalink
Fix script to re-write on each run
Browse files Browse the repository at this point in the history
- remove {{content}} as it renders in liquid
  • Loading branch information
Chris Del committed Feb 1, 2025
1 parent 0c568d1 commit 2f9684f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
68 changes: 44 additions & 24 deletions .github/scripts/get-contributing.sh
Original file line number Diff line number Diff line change
@@ -1,59 +1,78 @@
#!/bin/bash

DEST="../../en/resources/contributing.md"
# This script replaces the contents of a section with the contents from the annotated source address or local file paths inside the DEST file.

# This script replaces the contents of a section with the contents from
# the annotated source address.
# read contents of file into memory
DEST="../../en/resources/contributing.md"

# tracks the header level
# track the header level
level=''
# tracks repo & file for curl call
# tracks src for curl calls
src=''
# tracks file for local file copy
# tracks file paths for local file reads
local=''
while IFS= read -r line; do
# this section removes prev lines after file loads - src/load set to non-empty
while IFS= read -r line; do
# REMOVE PREVIOUS CONTENT SECTION
# if src or local tags are not empty
if [[ -n "$src" || -n "$local" ]]; then
# line not a horitzontal rule hr
# if current line not a horitzontal rule hr
if [[ "$line" != "----"* ]]; then
# if line eq level - level is num of ##s
# if line == level -> level is num of ##s
if [[ "$line" == "$level"'#'* ||
# line not a header)
# line not a header line
"$line" != '#'* ]]; then
continue
# skip line and rewrite over old content
continue
fi
fi
fi

# PRINT TO PAGE SECTION
src=''
local=''
# if line is header - assign level num
# if line is header -> assign level num
if [[ "$line" == '#'* ]]; then
# this is header before SRC/LOCAL anchors
title=${line##*\#}
level="${line:0:$((${#line} - ${#title}))}"
# src on page
# if header has (#id-of-link) or {#id-on-page} patterns
if [[ $line =~ (\(\#.*\))\. || "$line" =~ \{\#.*\} ]]; then
# isolate the matching part of line
match=${BASH_REMATCH[0]}
# remove match leaving rest
rest=${line//${match}}
# remove any # symbols from start
title_rest=${rest##*\#}
# slice rest to get only level
level="${rest:0:$((${#rest} - ${#title_rest}))}"
else
# any other headers -> before SRC/LOCAL pages anchors
header=${line##*\#}
level="${line:0:$((${#line} - ${#header}))}"
fi
# if line is src anchor in read file
elif [[ "$line" == '<!-- SRC:'* ]]; then
# remove the first 10 chars
src=${line:10}
# % remove from end until after white space -> leave src details
src=${src% *}
# local on page
# if line is local anchor in read file
elif [[ "$line" == '<!-- LOCAL:'* ]]; then
# remove the first 12 chars
local=${line:12}
# % remove from end until after white space -> leave local details
local=${local% *}
# leave only path to file
local=${local#* }
fi

# execute line to the page
echo "$line"

if [[ -n "$local" ]]; then
# cat file -> outputs full content of file at local path
cat "$local" | \
# remove the top 1# headers from cat'd file
sed -En '/^##|^[^#]/,$p' | \
# remove GH specific tags staring w '[!NOTE\] and next line
# remove GH MD specific tags start w '[!NOTE\] + following line
sed -E '/^>\[!NOTE\]*/{N;d;}' | \
# remove any lines with 'Not the Express JS Framework'
sed -E '/Not the Express JS Framework/I,$d' | \
# remove GH specific md tags
# change GH specific MD IMPORTANT tags to plain MD
sed -E 's/> \[!IMPORTANT\]/> **IMPORTANT:** /g'
echo
elif [[ -n "$src" ]]; then
Expand All @@ -65,8 +84,9 @@ while IFS= read -r line; do
sed -En '/^##|^[^#]/,$p' | \
# add additional # every header
sed 's/^#/&'"${level:1}"'/g' | \
# format gh links when match
# format GH links when match
sed -E 's/(\[[^]]*\])\(([^):#]*)\)/\1(https:\/\/github.com\/'"$(sed 's/\//\\\//g' <<< "$repo")"'\/blob\/master\/\2)/g'
echo
fi
# read in dest file then write back to file
done <<<"$(< $DEST)" > $DEST
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ But just in case you need a little extra explanation, this section below outline
- These are used to import text content for reuse across pages, such as the API documentation, e.g., `_includes > api > en > 5x`, which is included in every language.
- These are used to include the page components that make up site-wide user interface and periphery structure, e.g., Header, Footer, etc.
- `_layouts` are the templates used to wrap the site's individual pages.
- These are used to display the structure of the site's periphery, such as the header and footer, and for injecting and displaying individual markdown pages inside the `{{ content }}` tag.
- These are used to display the structure of the site's periphery, such as the header and footer, and for injecting and displaying individual markdown pages inside the `content` tag.

**Blog Markdown Files**
- These files make up the individual blog posts. If you want to contribute a blog post please
Expand Down

0 comments on commit 2f9684f

Please sign in to comment.