Skip to content

Commit 2f9684f

Browse files
author
Chris Del
committed
Fix script to re-write on each run
- remove {{content}} as it renders in liquid
1 parent 0c568d1 commit 2f9684f

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed
Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,78 @@
11
#!/bin/bash
22

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

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

8-
# tracks the header level
8+
# track the header level
99
level=''
10-
# tracks repo & file for curl call
10+
# tracks src for curl calls
1111
src=''
12-
# tracks file for local file copy
12+
# tracks file paths for local file reads
1313
local=''
14-
while IFS= read -r line; do
15-
# this section removes prev lines after file loads - src/load set to non-empty
14+
while IFS= read -r line; do
15+
# REMOVE PREVIOUS CONTENT SECTION
16+
# if src or local tags are not empty
1617
if [[ -n "$src" || -n "$local" ]]; then
17-
# line not a horitzontal rule hr
18+
# if current line not a horitzontal rule hr
1819
if [[ "$line" != "----"* ]]; then
19-
# if line eq level - level is num of ##s
20+
# if line == level -> level is num of ##s
2021
if [[ "$line" == "$level"'#'* ||
21-
# line not a header)
22+
# line not a header line
2223
"$line" != '#'* ]]; then
23-
continue
24+
# skip line and rewrite over old content
25+
continue
2426
fi
2527
fi
2628
fi
2729

30+
# PRINT TO PAGE SECTION
2831
src=''
2932
local=''
30-
# if line is header - assign level num
33+
# if line is header -> assign level num
3134
if [[ "$line" == '#'* ]]; then
32-
# this is header before SRC/LOCAL anchors
33-
title=${line##*\#}
34-
level="${line:0:$((${#line} - ${#title}))}"
35-
# src on page
35+
# if header has (#id-of-link) or {#id-on-page} patterns
36+
if [[ $line =~ (\(\#.*\))\. || "$line" =~ \{\#.*\} ]]; then
37+
# isolate the matching part of line
38+
match=${BASH_REMATCH[0]}
39+
# remove match leaving rest
40+
rest=${line//${match}}
41+
# remove any # symbols from start
42+
title_rest=${rest##*\#}
43+
# slice rest to get only level
44+
level="${rest:0:$((${#rest} - ${#title_rest}))}"
45+
else
46+
# any other headers -> before SRC/LOCAL pages anchors
47+
header=${line##*\#}
48+
level="${line:0:$((${#line} - ${#header}))}"
49+
fi
50+
# if line is src anchor in read file
3651
elif [[ "$line" == '<!-- SRC:'* ]]; then
52+
# remove the first 10 chars
3753
src=${line:10}
54+
# % remove from end until after white space -> leave src details
3855
src=${src% *}
39-
# local on page
56+
# if line is local anchor in read file
4057
elif [[ "$line" == '<!-- LOCAL:'* ]]; then
58+
# remove the first 12 chars
4159
local=${line:12}
60+
# % remove from end until after white space -> leave local details
4261
local=${local% *}
62+
# leave only path to file
4363
local=${local#* }
4464
fi
45-
65+
# execute line to the page
4666
echo "$line"
4767

4868
if [[ -n "$local" ]]; then
69+
# cat file -> outputs full content of file at local path
4970
cat "$local" | \
5071
# remove the top 1# headers from cat'd file
5172
sed -En '/^##|^[^#]/,$p' | \
52-
# remove GH specific tags staring w '[!NOTE\] and next line
73+
# remove GH MD specific tags start w '[!NOTE\] + following line
5374
sed -E '/^>\[!NOTE\]*/{N;d;}' | \
54-
# remove any lines with 'Not the Express JS Framework'
55-
sed -E '/Not the Express JS Framework/I,$d' | \
56-
# remove GH specific md tags
75+
# change GH specific MD IMPORTANT tags to plain MD
5776
sed -E 's/> \[!IMPORTANT\]/> **IMPORTANT:** /g'
5877
echo
5978
elif [[ -n "$src" ]]; then
@@ -65,8 +84,9 @@ while IFS= read -r line; do
6584
sed -En '/^##|^[^#]/,$p' | \
6685
# add additional # every header
6786
sed 's/^#/&'"${level:1}"'/g' | \
68-
# format gh links when match
87+
# format GH links when match
6988
sed -E 's/(\[[^]]*\])\(([^):#]*)\)/\1(https:\/\/github.com\/'"$(sed 's/\//\\\//g' <<< "$repo")"'\/blob\/master\/\2)/g'
7089
echo
7190
fi
91+
# read in dest file then write back to file
7292
done <<<"$(< $DEST)" > $DEST

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ But just in case you need a little extra explanation, this section below outline
8181
- 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.
8282
- These are used to include the page components that make up site-wide user interface and periphery structure, e.g., Header, Footer, etc.
8383
- `_layouts` are the templates used to wrap the site's individual pages.
84-
- 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.
84+
- 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.
8585

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

0 commit comments

Comments
 (0)