Skip to content

Commit

Permalink
GitHub Pages Script Updates (kodecocodes#670)
Browse files Browse the repository at this point in the history
* Move inline css to the main stylesheet - github-light.css & parse the repo README to
html instead of generating one.

* Minor clean up

* Fix image link

* Parse other markdown files
  • Loading branch information
Hai Nguyen authored and vincentngo committed Dec 2, 2017
1 parent a5d3185 commit aa6e2bf
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 74 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ script:
- xcodebuild test -project ./Ternary\ Search\ Tree/Tests/Tests.xcodeproj -scheme Tests | xcpretty -f `xcpretty-travis-formatter`

after_success:

- if [[ "$TRAVIS_BRANCH" == "master" ]]; then ./gfm-render.sh; fi
8 changes: 4 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Swift Algorithm Club](/Images/SwiftAlgorithm-410-transp.png)
![Swift Algorithm Club](Images/SwiftAlgorithm-410-transp.png)

# Welcome to the Swift Algorithm Club!

Expand Down Expand Up @@ -156,14 +156,14 @@ Most of the time using just the built-in `Array`, `Dictionary`, and `Set` types
- [Splay Tree](Splay%20Tree/). A self balancing binary search tree that enables fast retrieval of recently updated elements.
- [Threaded Binary Tree](Threaded%20Binary%20Tree/). A binary tree that maintains a few extra variables for cheap and fast in-order traversals.
- [Segment Tree](Segment%20Tree/). Can quickly compute a function over a portion of an array.
- [Lazy Propagation](https://github.com/raywenderlich/swift-algorithm-club/tree/master/Segment%20Tree/LazyPropagation)
- [Lazy Propagation](https://github.com/raywenderlich/swift-algorithm-club/tree/master/Segment%20Tree/LazyPropagation)
- kd-Tree
- [Heap](Heap/). A binary tree stored in an array, so it doesn't use pointers. Makes a great priority queue.
- Fibonacci Heap
- [Trie](Trie/). A special type of tree used to store associative data structures.
- [B-Tree](B-Tree/). A self-balancing search tree, in which nodes can have more than two children.
- [QuadTree](QuadTree/). A tree with 4 children.
- [Octree](Octree/). A tree with 8 children.
- [Octree](Octree/). A tree with 8 children.

### Hashing

Expand Down Expand Up @@ -208,7 +208,7 @@ For more information, check out these great books:
- [The Algorithm Design Manual](http://www.algorist.com) by Skiena
- [Elements of Programming Interviews](http://elementsofprogramminginterviews.com) by Aziz, Lee, Prakash
- [Algorithms](http://www.cs.princeton.edu/~rs/) by Sedgewick
- [Grokking Algorithms](https://www.manning.com/books/grokking-algorithms) by Aditya Bhargava
- [Grokking Algorithms](https://www.manning.com/books/grokking-algorithms) by Aditya Bhargava

The following books are available for free online:

Expand Down
175 changes: 105 additions & 70 deletions gfm-render.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,108 @@
#!/usr/bin/env bash

# $1 - readme
set -e

# $1 - readme file name
function render_markdown_to_html {
# escape escaping characters
if [[ $(uname) == "Darwin" ]]; then
content=$(
cat "$1" \
| sed 's/\\/\\\\/g' \
| sed 's/"/\\"/g' \
| sed $'s/\t/\\\\t/g' \
| sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\\n/g' \
)
else
content=$(
cat "$1" \
| sed 's/\\/\\\\/g' \
| sed 's/"/\\"/g' \
| sed 's/\t/\\t/g' \
| sed ':a;N;$!ba;s/\n/\\n/g' \
)
fi
# escape escaping characters on Darwin only
content=$(
cat "$1" \
| sed 's/\\/\\\\/g' \
| sed 's/"/\\"/g' \
| sed $'s/\t/\\\\t/g' \
| sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\\n/g' \
)

# network call to GitHub API
json="{\"text\":\"$content\",\"mode\":\"gfm\",\"context\":\"$USERNAME/swift-algorithm-club\"}"
echo -e "$(curl -s --data "$json" -u $USERNAME:$TOKEN https://api.github.com/markdown)"
}

# $1 - comment
function push_to_gh_pages {
git checkout -b gh-pages
git add .
git commit -m "$1"
git push -f https://$TOKEN@github.com/$USERNAME/swift-algorithm-club.git gh-pages
}

# download github systax highlight stylesheet
echo "> Downloading github-light.css..."
curl -s -O https://raw.githubusercontent.com/primer/github-syntax-light/master/lib/github-light.css

# slightly modify the main stylesheet
echo "> Modifying github-light.css..."
cat >> github-light.css << EOF
#container {
margin: 0 auto;
width: 75%;
min-width: 768px;
max-width: 896px;
position: relative;
}
body {
font-size: 18px;
}
code {
padding: 0.2em;
margin: 0;
font-size: 85%;
background-color: #f6f8fa;
line-height: 1.45;
border-radius: 3px
}
pre code {
padding: 0px;
background-color: transparent;
}
.highlight {
margin: 0px;
padding: 0px 16px;
font-size: 85%;
line-height: 1.45;
overflow: auto;
background-color: #f6f8fa;
border-radius: 3px;
}
@media (max-width: 768px) {
#container {
position: absolute;
margin: 0;
width: 100%;
height: 100%;
min-width: 100%;
}
}
EOF

# other markdown articles
for title in "What are Algorithms" "Big-O Notation" "Algorithm Design" "Why Algorithms"; do
echo "> Generating $title.html..."

cat > "$title.html" << EOF
<!DOCTYPE html>
<head>
<title>$title</title>
<link rel="stylesheet" type="text/css" href="github-light.css">
</head>
<body>
<div id="container">$(render_markdown_to_html "$title.markdown")</div>
</body>
</html>
EOF
done

# if index.html does not exist, create one;
# otherwise, empty its content.
if [[ -z index.html ]]; then
touch index.html
else
> index.html
fi
echo "> Generating index.html..."
cat > index.html << EOF
<!DOCTYPE html>
<head>
<title>Swift Algorithm Club</title>
<link rel="stylesheet" type="text/css" href="github-light.css">
</head>
<body>
<div id="container">$(render_markdown_to_html README.markdown | sed 's/.markdown/.html/g')</div>
</body>
</html>
EOF

# iterate immediate directories
find . -maxdepth 1 -type d | while read folder; do
Expand All @@ -54,53 +112,30 @@ find . -maxdepth 1 -type d | while read folder; do
if [[ -f $folder/README.md ]]; then readme="$folder/README.md"; fi
if [[ -f $folder/README.markdown ]]; then readme="$folder/README.markdown"; fi

# exclude the repository's README
if [[ !(-z $readme) && ($readme != "./README.markdown") ]]; then
name=$(basename "$folder")
echo "> Generating $name/index.html..."
# skip if there is no README or it it the README of the repository
if [[ (-z $readme) || $readme == "./README.markdown" ]]; then continue; fi

# render README to HTML
name=$(basename "$folder")
echo "> Generating $name/index.html..."

cat > "$folder/index.html" << EOF
cat > "$folder/index.html" << EOF
<!DOCTYPE html>
<head>
<title>$name</title>
<link rel="stylesheet" type="text/css" href="../github-light.css">
<style>
body {
font-size: 18px;
}
code {
padding: 0.2em;
margin: 0;
font-size: 85%;
background-color: #f6f8fa;
line-height: 1.45;
border-radius: 3px
}
pre code {
padding: 0px;
background-color: transparent;
}
.highlight {
margin: 0px;
padding: 0px 16px;
font-size: 85%;
line-height: 1.45;
overflow: auto;
background-color: #f6f8fa;
border-radius: 3px;
}
</style>
</head>
<body>
$(render_markdown_to_html "$readme")
<div id="container">$(render_markdown_to_html "$readme")</div>
</body>
</html>
EOF
# temporarily write the list of HTML filenames to the main index.html
echo "$lists<li><a href=\"$name/index.html\">$name</a></li>" >> index.html
fi
done

echo "<!DOCTYPE html><body><h1>Swift Algorithm</h1><ul>$(echo -n $(cat index.html))</ul></body></html>" > index.html

# push to gh-pages
if [[ $CI = true ]]; then push_to_gh_pages "Generated by TravisCI on $(date +%D)"; fi
if [[ $CI = true ]]; then
git checkout -b gh-pages
git add .
git commit -m "$Generated by TravisCI on $(date +%D)"
git push -f https://$TOKEN@github.com/$USERNAME/swift-algorithm-club.git gh-pages
fi

0 comments on commit aa6e2bf

Please sign in to comment.