diff --git a/.travis.yml b/.travis.yml index 7cd02c9bc..edf1cf89f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.markdown b/README.markdown index b15bd1527..46544682e 100644 --- a/README.markdown +++ b/README.markdown @@ -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! @@ -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 @@ -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: diff --git a/gfm-render.sh b/gfm-render.sh index 09c026d55..4e18c8560 100755 --- a/gfm-render.sh +++ b/gfm-render.sh @@ -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 + + + $title + + + +
$(render_markdown_to_html "$title.markdown")
+ + +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 + + + Swift Algorithm Club + + + +
$(render_markdown_to_html README.markdown | sed 's/.markdown/.html/g')
+ + +EOF # iterate immediate directories find . -maxdepth 1 -type d | while read folder; do @@ -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 + $name - - $(render_markdown_to_html "$readme") +
$(render_markdown_to_html "$readme")
EOF - # temporarily write the list of HTML filenames to the main index.html - echo "$lists
  • $name
  • " >> index.html - fi done -echo "

    Swift Algorithm

    " > 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