]>
Commit | Line | Data |
---|---|---|
a9d77a20 FM |
1 | #!/usr/bin/env bash |
2 | ||
3 | # This is the initial commit of this project. | |
4 | # This is useful to list content of the first tagged version. | |
5 | rootCommit="c468e930cf7f15c709bf8890f197135a62858f16" | |
6 | ||
7 | function parentTag { | |
8 | local tag=$1 | |
9 | git describe --abbrev=0 --tags "${tag}^" 2>/dev/null || echo "${rootCommit}" | |
10 | } | |
11 | ||
12 | function prettyLogUndocumentedTag { | |
13 | local tag=$1; | |
14 | cat <<-HTML | |
15 | <dt> | |
16 | <h2> | |
17 | (${tag}) Not generated | |
18 | </h2> | |
19 | </dt> | |
20 | HTML | |
21 | } | |
22 | ||
23 | function gitAuthor { | |
24 | local tag="$1" | |
25 | git log -n1 --pretty="%an" "${tag}" | |
26 | } | |
27 | ||
28 | function linkToTaggedDocumentation { | |
29 | local tag="$1" | |
30 | cat <<-HTML | |
31 | <a href="${tag}/index.html"> | |
32 | <button> | |
33 | <small>Go to </small> | |
34 | <strong>${tag}</strong> | |
35 | <small> released by </small> | |
36 | <strong>$(gitAuthor "${tag}")</strong> | |
37 | </button> | |
38 | </a> | |
39 | HTML | |
40 | } | |
41 | ||
42 | function contentOfTaggedDocumentation { | |
43 | local tag=$1; | |
44 | local content | |
45 | content=$(git log --pretty="%ad | %h | %s" --date=short "$(parentTag "${tag}")..${tag}") | |
46 | echo "<pre>${content}</pre>" | |
47 | } | |
48 | ||
49 | function prettyLogTag { | |
50 | local tag=$1 | |
51 | cat <<-HTML | |
52 | <dt>$(linkToTaggedDocumentation "${tag}")</dt> | |
53 | <dd>$(contentOfTaggedDocumentation "${tag}")</dd> | |
54 | HTML | |
55 | } | |
56 | ||
57 | function formatTags { | |
58 | local webRoot="$1" | |
59 | while read -r tag | |
60 | do | |
61 | if [ -d "${webRoot}/${tag}" ] | |
62 | then | |
63 | prettyLogTag "$tag" | |
64 | else | |
65 | prettyLogUndocumentedTag "$tag" | |
66 | fi | |
67 | done | |
68 | } | |
69 | ||
70 | function listTags { | |
71 | git tag --list "v20??-??-??" --sort="-refname" | |
72 | } | |
73 | ||
74 | function generateIndex { | |
75 | local webRoot="$1" | |
76 | cat <<-HTML | |
77 | <!DOCTYPE html> | |
78 | <html> | |
79 | <meta charset="UTF-8"> | |
80 | <head> | |
81 | <link rel="stylesheet" href="https://cdn.rawgit.com/yegor256/tacit/gh-pages/tacit-css-1.3.4.min.css"/> | |
82 | </head> | |
83 | <body> | |
84 | <section> | |
85 | <article> | |
86 | <h1>Available documentations</h1> | |
87 | <hr> | |
88 | <dl> | |
89 | $(listTags | formatTags "${webRoot}") | |
90 | </dl> | |
91 | </section> | |
92 | </article> | |
93 | </section> | |
94 | </body> | |
95 | </html> | |
96 | HTML | |
97 | } | |
98 | ||
99 | function generateDoc { | |
100 | local webRoot="$1" | |
101 | local currentTag="$2" | |
102 | local docRoot="$3" | |
103 | local tagWebRoot="${webRoot}/${currentTag}" | |
104 | if [[ -z "$webRoot" ]] | |
105 | then | |
106 | echo "Undefined webRoot directory" | |
107 | exit 1 | |
108 | fi | |
109 | if [[ -z "$currentTag" ]] | |
110 | then | |
111 | echo "Undefined current tag" | |
112 | exit 1 | |
113 | fi | |
114 | if [[ -z "$docRoot" ]] | |
115 | then | |
116 | echo "Undefined documentation root" | |
117 | exit 1 | |
118 | fi | |
119 | echo "Documentation root: ${docRoot}" | |
120 | mkdir -p "${webRoot}"; | |
121 | cp -r "${docRoot}" "${tagWebRoot}" | |
122 | generateIndex "${webRoot}" > "${webRoot}/index.html" | |
123 | } | |
124 | ||
125 | generateDoc "$1" "$2" "$3" |