|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# |
| 4 | +# @file esp8266-arudino-doc.bash |
| 5 | +# @author Ivan Grokhotkov (https://github.com/igrr) |
| 6 | +# @author Pascal Gollor (https://github.com/pgollor) |
| 7 | +# |
| 8 | +# |
| 9 | +# This script build the documentation for a specific Arduino ESP8266 release version. |
| 10 | +# |
| 11 | +# Packages needed by this script: |
| 12 | +# * linux commands: ln, cp, mkdir, rm, wget |
| 13 | +# * git |
| 14 | +# * jekyll |
| 15 | +# |
| 16 | +# ruby libraries: |
| 17 | +# * redcarpet |
| 18 | +# * rb-pygments |
| 19 | +# |
| 20 | +# gem install [lib] |
| 21 | +# |
| 22 | + |
| 23 | + |
| 24 | +# some variable definitions |
| 25 | +tmp_path=$1 |
| 26 | +arduinoESP_src="$tmp_path/arduino" |
| 27 | +version="$(git --work-tree=$arduinoESP_src describe --tags --always)" |
| 28 | +release_date=$(date "+%b_%d,_%Y") # format for badge link |
| 29 | +build_date=$(date "+%b %d, %Y") |
| 30 | +destination_path="$tmp_path/doc" |
| 31 | +doc_template_url="https://github.com/igrr/esp8266-arduino-docs.git" |
| 32 | +url="http://esp8266.github.io/Arduino" |
| 33 | + |
| 34 | +# control output |
| 35 | +echo "Arduino ESP8266 source dir: "$arduinoESP_src |
| 36 | +echo " version: "$version |
| 37 | +echo " release date: "$release_date |
| 38 | +echo " build date: "$build_date |
| 39 | +echo " put documentation into: "$destination_path |
| 40 | +echo "documentatino template url: "$doc_template_url |
| 41 | +echo " url: "$url |
| 42 | + |
| 43 | +# continue? |
| 44 | +read -e -p "Dou you wish to continue (y/n)? " -n 1 -i "y" decision |
| 45 | +if echo "$decision" | grep -iq "^y" ;then |
| 46 | + echo "okay" |
| 47 | +else |
| 48 | + echo "bye bye" |
| 49 | + exit |
| 50 | +fi |
| 51 | + |
| 52 | + |
| 53 | +# delete old doc dir |
| 54 | +rm -fR $destination_path |
| 55 | + |
| 56 | +# create destination directories |
| 57 | +mkdir -p $destination_path/src |
| 58 | +mkdir -p $destination_path/$version |
| 59 | + |
| 60 | +# copy doc files to destination soruce dir |
| 61 | +cp -R $arduinoESP_src/doc/* $destination_path/src |
| 62 | + |
| 63 | +# download doc template |
| 64 | +git clone $doc_template_url $destination_path/build |
| 65 | + |
| 66 | +# create versions.html file |
| 67 | + |
| 68 | +# ... read verions |
| 69 | +pushd $arduinoESP_src |
| 70 | +old_versions=$(git ls-tree -d --name-only remotes/origin/gh-pages versions/ | sed -e 's/versions\///g') |
| 71 | +popd |
| 72 | + |
| 73 | +echo -e "\nREAD old versions:" |
| 74 | + |
| 75 | +found_current_version="false" |
| 76 | +case "${old_versions[@]}" in *"$version"*) found_current_version="true" ;; esac |
| 77 | + |
| 78 | +if [ "$found_current_version" = "false" ]; then |
| 79 | + old_versions=$version" "$old_versions |
| 80 | +fi |
| 81 | + |
| 82 | +# ... fill versions.html |
| 83 | +for VER in $old_versions |
| 84 | +do |
| 85 | + echo $VER |
| 86 | + echo "<li><a href=\"versions/$VER\">$VER</a></li>" >> $destination_path/build/_includes/versions.html |
| 87 | +done |
| 88 | +echo "" |
| 89 | + |
| 90 | + |
| 91 | +# into build dir |
| 92 | +pushd $destination_path/build |
| 93 | + |
| 94 | +# link documentation source |
| 95 | +ln -s ../src doc |
| 96 | + |
| 97 | +# link documentation destination |
| 98 | +ln -s ../$version _site |
| 99 | + |
| 100 | +# add subtitle and basurl |
| 101 | +echo "url: \"$url\"" > _config_local.yml |
| 102 | +echo "subtitle: \"ver. $version, built on $build_date\"" >> _config_local.yml |
| 103 | +echo "baseurl: /Arduino/versions/$version" >> _config_local.yml |
| 104 | + |
| 105 | +# build with jekyll |
| 106 | +jekyll build --config _config.yml,_config_local.yml |
| 107 | + |
| 108 | +popd |
| 109 | + |
| 110 | + |
| 111 | +# grab badge |
| 112 | +wget -q -O $destination_path/$version/badge.svg "https://img.shields.io/badge/updated-$release_date-blue.svg" |
| 113 | + |
0 commit comments