build: Refactor document generation to be faster and support partials.

Article header and footer are now partials, making them easy to exclude from license files.
This commit is contained in:
Bradley Sepos 2016-03-25 20:48:36 -04:00
parent 8c567a150e
commit cc0e6b0e75
12 changed files with 71 additions and 54 deletions

View File

@ -57,7 +57,8 @@ function build_source {
local SOURCE YAML META_Title META_Project META_Project_URL META_Project_Version META_Language META_Language_Code META_Text_Encoding META_Authors META_Copyright META_License META_License_URL
SOURCE="${1}"
BASE="${SOURCE%.markdown}"
DEST="${SOURCE%.markdown}"
DEST_NAME="${DEST##*/}"
# check for yaml header
META=false
@ -66,40 +67,50 @@ function build_source {
fi
if [[ "${META}" == true ]]; then
# split yaml and markdown
awk '{ drop = 0; } /^---$/ { if (NR==1) { drop = 1 } else if (NR>1) { exit } else { drop = 0; next } } drop == 0 { print }' "${SOURCE}" > "${BASE}.yaml"
mv "${SOURCE}" "${BASE}-temp.markdown"
tail -n +$(wc -l "${BASE}.yaml" | awk '{ print $1+3 }') "${BASE}-temp.markdown" > "${SOURCE}"
rm -f "${BASE}-temp.markdown"
awk '{ drop = 0; } /^---$/ { if (NR==1) { drop = 1 } else if (NR>1) { exit } else { drop = 0; next } } drop == 0 { print }' "${SOURCE}" > "${DEST}.yaml"
mv "${SOURCE}" "${DEST}.markdown.temp"
tail -n +$(wc -l "${DEST}.yaml" | awk '{ print $1+3 }') "${DEST}.markdown.temp" > "${SOURCE}"
rm -f "${DEST}.markdown.temp"
# parse yaml
eval $(parse_yaml "${BASE}.yaml" "META_")
eval $(parse_yaml "${DEST}.yaml" "META_")
fi
# generate document using template
DOCUMENT_Content=$("${MARKDOWN}" -fdlextra -ffencedcode -ffootnote -fgithubtags "${SOURCE}")
DOCUMENT_Content="${DOCUMENT_Content:-}"
VAR_Content="{{ document.content }}"
touch "${BASE}.html"
while IFS='' read TEMPLATE || [[ -n "${TEMPLATE}" ]]; do
echo "${TEMPLATE//$VAR_Content/$DOCUMENT_Content}" \
| sed -E 's|{{[ ]*meta\.title[ ]*}}|'"${META_Title:-}"'|g' \
| sed -E 's|{{[ ]*meta\.project[ ]*}}|'"${META_Project:-}"'|g' \
| sed -E 's|{{[ ]*meta\.project-url[ ]*}}|'"${META_Project_URL:-}"'|g' \
| sed -E 's|{{[ ]*meta\.project-version[ ]*}}|'"${META_Project_Version:-}"'|g' \
| sed -E 's|{{[ ]*meta\.language[ ]*}}|'"${META_Language:-}"'|g' \
| sed -E 's|{{[ ]*meta\.language-code[ ]*}}|'"${META_Language_Code:-}"'|g' \
| sed -E 's|{{[ ]*meta\.text-encoding[ ]*}}|'"${META_Text_Encoding:-}"'|g' \
| sed -E 's|{{[ ]*meta\.authors[ ]*}}|'"${META_Authors:-}"'|g' \
| sed -E 's|{{[ ]*meta\.copyright[ ]*}}|'"${META_Copyright:-}"'|g' \
| sed -E 's|{{[ ]*meta\.license[ ]*}}|'"${META_License:-}"'|g' \
| sed -E 's|{{[ ]*meta\.license-abbr[ ]*}}|'"${META_License_Abbr:-}"'|g' \
| sed -E 's|{{[ ]*meta\.license-url[ ]*}}|'"${META_License_URL:-}"'|g' \
| sed -E 's|{{[ ]*base\.relpath[ ]*}}|'"${BASE_RELPATH:-}"'|g' \
>> "${BASE}.html"
done < "${TEMPLATE_DIR}/document.html"
DOCUMENT_Content="${DEST}.html.temp"
"${MARKDOWN}" -fdlextra -ffencedcode -ffootnote -fgithubtags "${SOURCE}" > "${DOCUMENT_Content}"
cp "${TEMPLATE_Document}" "${DEST}.html"
if [[ "${DEST_NAME}" == "license" ]] || [[ "${DEST_NAME}" == "license-summary" ]]; then
sed -E \
-e 's|{{[ ]*template\.header[ ]*}}||g' \
-e 's|{{[ ]*template\.footer[ ]*}}||g' \
-i .sedbak "${DEST}.html"
fi
sed -E \
-e '/{{[ ]*template\.header[ ]*}}/r '"${TEMPLATE_Header}"'' -e '/{{[ ]*template\.header[ ]*}}/d' \
-e '/{{[ ]*document\.content[ ]*}}/r '"${DOCUMENT_Content}"'' -e '/{{[ ]*document\.content[ ]*}}/d' \
-e '/{{[ ]*template\.footer[ ]*}}/r '"${TEMPLATE_Footer}"'' -e '/{{[ ]*template\.footer[ ]*}}/d' \
-i .sedbak "${DEST}.html"
sed -E \
-e 's|{{[ ]*meta\.title[ ]*}}|'"${META_Title:-}"'|g' \
-e 's|{{[ ]*meta\.project[ ]*}}|'"${META_Project:-}"'|g' \
-e 's|{{[ ]*meta\.project-url[ ]*}}|'"${META_Project_URL:-}"'|g' \
-e 's|{{[ ]*meta\.project-version[ ]*}}|'"${META_Project_Version:-}"'|g' \
-e 's|{{[ ]*meta\.language[ ]*}}|'"${META_Language:-}"'|g' \
-e 's|{{[ ]*meta\.language-code[ ]*}}|'"${META_Language_Code:-}"'|g' \
-e 's|{{[ ]*meta\.text-encoding[ ]*}}|'"${META_Text_Encoding:-}"'|g' \
-e 's|{{[ ]*meta\.authors[ ]*}}|'"${META_Authors:-}"'|g' \
-e 's|{{[ ]*meta\.copyright[ ]*}}|'"${META_Copyright:-}"'|g' \
-e 's|{{[ ]*meta\.license[ ]*}}|'"${META_License:-}"'|g' \
-e 's|{{[ ]*meta\.license-abbr[ ]*}}|'"${META_License_Abbr:-}"'|g' \
-e 's|{{[ ]*meta\.license-url[ ]*}}|'"${META_License_URL:-}"'|g' \
-e 's|{{[ ]*base\.relpath[ ]*}}|'"${BASE_RELPATH:-}"'|g' \
-i .sedbak "${DEST}.html"
# clean up
rm -f "${BASE}.markdown"
rm -f "${BASE}.yaml"
rm -f "${DEST}.markdown"
rm -f "${DEST}.yaml"
rm -f "${DEST}.html.temp"
rm -f "${DEST}.html.sedbak"
}
@ -124,6 +135,11 @@ if [[ ! -d "${TEMPLATE_DIR}" ]] || [[ ! -e "${TEMPLATE_DIR}/document.html" ]]; t
exit 1
fi
# template vars
TEMPLATE_Document="${TEMPLATE_DIR}/document.html"
TEMPLATE_Header="${TEMPLATE_DIR}/header.html"
TEMPLATE_Footer="${TEMPLATE_DIR}/footer.html"
# clean
rm -rf "${DOCS_DIR}"/*

View File

@ -68,6 +68,7 @@
<p>These instructions are taken directly from Apple&rsquo;s OS X Gatekeeper support documents. You can learn more about Gatekeeper <a href="https://support.apple.com/kb/PH21769?locale=en_US">here</a> and <a href="https://support.apple.com/en-us/HT202491">here</a>.<a href="#fnref:2" rev="footnote">&#8617;</a></p></li>
</ol>
</div>
<footer>
<p><span class="authorship">This article is part of the <a href="../../../" title="HandBrake Documentation">HandBrake Documentation</a> and was written by Bradley Sepos.</span> <span class="contributing">Join us on GitHub to contribute your thoughts and ideas, and to suggest any necessary corrections.</span></p>
<small class="copyright">Copyright 2016 HandBrake Team. <a href="../../../license-summary.html" title="License Summary"><abbr title="Creative Commons Attribution-ShareAlike 4.0 International">CC BY-SA 4.0</abbr></a>.</small>

View File

@ -289,6 +289,7 @@
</li>
<li>Advanced preferences</li>
</ul>
<footer>
<p><span class="authorship">This article is part of the <a href="../../" title="HandBrake Documentation">HandBrake Documentation</a> and was written by Bradley Sepos.</span> <span class="contributing">Join us on GitHub to contribute your thoughts and ideas, and to suggest any necessary corrections.</span></p>
<small class="copyright">Copyright 2016 HandBrake Team. <a href="../../license-summary.html" title="License Summary"><abbr title="Creative Commons Attribution-ShareAlike 4.0 International">CC BY-SA 4.0</abbr></a>.</small>

View File

@ -66,6 +66,7 @@
<p>Without special software, it is not possible to directly copy VIDEO_TS and BDMV folders from copy-protected discs.<a href="#fnref:3" rev="footnote">&#8617;</a></p></li>
</ol>
</div>
<footer>
<p><span class="authorship">This article is part of the <a href="../../../" title="HandBrake Documentation">HandBrake Documentation</a> and was written by Bradley Sepos.</span> <span class="contributing">Join us on GitHub to contribute your thoughts and ideas, and to suggest any necessary corrections.</span></p>
<small class="copyright">Copyright 2016 HandBrake Team. <a href="../../../license-summary.html" title="License Summary"><abbr title="Creative Commons Attribution-ShareAlike 4.0 International">CC BY-SA 4.0</abbr></a>.</small>

View File

@ -67,6 +67,7 @@
<p>Learn more about <a href="https://en.wikipedia.org/wiki/Optimum_HDTV_viewing_distance">optimum viewing distances for high definition TV displays</a>.<a href="#fnref:4" rev="footnote">&#8617;</a></p></li>
</ol>
</div>
<footer>
<p><span class="authorship">This article is part of the <a href="../../../" title="HandBrake Documentation">HandBrake Documentation</a> and was written by Bradley Sepos.</span> <span class="contributing">Join us on GitHub to contribute your thoughts and ideas, and to suggest any necessary corrections.</span></p>
<small class="copyright">Copyright 2016 HandBrake Team. <a href="../../../license-summary.html" title="License Summary"><abbr title="Creative Commons Attribution-ShareAlike 4.0 International">CC BY-SA 4.0</abbr></a>.</small>

View File

@ -68,6 +68,7 @@
<p>HD-DVD playlists are not fully supported. Individual files/streams may work.<a href="#fnref:3" rev="footnote">&#8617;</a></p></li>
</ol>
</div>
<footer>
<p><span class="authorship">This article is part of the <a href="../../../" title="HandBrake Documentation">HandBrake Documentation</a> and was written by Bradley Sepos.</span> <span class="contributing">Join us on GitHub to contribute your thoughts and ideas, and to suggest any necessary corrections.</span></p>
<small class="copyright">Copyright 2016 HandBrake Team. <a href="../../../license-summary.html" title="License Summary"><abbr title="Creative Commons Attribution-ShareAlike 4.0 International">CC BY-SA 4.0</abbr></a>.</small>

View File

@ -11,9 +11,7 @@
</head>
<body>
<article class="docs">
<header>
<div class="breadcrumbs">English Docs > HandBrake Latest > License Summary</div>
</header>
<h1>License Summary</h1>
<p>HandBrake Documentation (this work) is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.</p>
@ -22,8 +20,9 @@
<h2>You are free to:</h2>
<p><strong>Share</strong> — copy and distribute the material in any medium or format for any purpose, even commercially
<strong>Adapt</strong> — remix, transform, and build upon the material for any purpose, even commercially</p>
<p><strong>Share</strong> — copy and distribute the material in any medium or format for any purpose, even commercially</p>
<p><strong>Adapt</strong> — remix, transform, and build upon the material for any purpose, even commercially</p>
<p>The licensor cannot revoke these freedoms as long as you follow the license terms.</p>
@ -47,10 +46,8 @@
<p>The license prohibits application of effective technological measures, defined with reference to Article 11 of the WIPO Copyright Treaty. <a href="https://wiki.creativecommons.org/wiki/License_Versions#Application_of_effective_technological_measures_by_users_of_CC-licensed_works_prohibited">More info on application of effective technological measures</a>.<a href="#fnref:4" rev="footnote">&#8617;</a></p></li>
</ol>
</div>
<footer>
<p><span class="authorship">This article is part of the <a href="" title="HandBrake Documentation">HandBrake Documentation</a> and was written by Bradley Sepos.</span> <span class="contributing">Join us on GitHub to contribute your thoughts and ideas, and to suggest any necessary corrections.</span></p>
<small class="copyright">Copyright 2016 HandBrake Team. <a href="license-summary.html" title="License Summary"><abbr title="Creative Commons Attribution-ShareAlike 4.0 International">CC BY-SA 4.0</abbr></a>.</small>
</footer>
</article>
</body>
</html>

View File

@ -11,9 +11,7 @@
</head>
<body>
<article class="docs">
<header>
<div class="breadcrumbs">English Docs > HandBrake Latest > License</div>
</header>
<h1>Creative Commons Attribution-ShareAlike 4.0 International Public License</h1>
<p>By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License (&ldquo;Public License&rdquo;). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.</p>
@ -163,10 +161,8 @@ For the avoidance of doubt, this Section 6(b) does not affect any right the Lice
<li>No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.</li>
<li>Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.</li>
</ol>
<footer>
<p><span class="authorship">This article is part of the <a href="" title="HandBrake Documentation">HandBrake Documentation</a> and was written by Bradley Sepos.</span> <span class="contributing">Join us on GitHub to contribute your thoughts and ideas, and to suggest any necessary corrections.</span></p>
<small class="copyright">Copyright 2016 HandBrake Team. <a href="license-summary.html" title="License Summary"><abbr title="Creative Commons Attribution-ShareAlike 4.0 International">CC BY-SA 4.0</abbr></a>.</small>
</footer>
</article>
</body>
</html>

View File

@ -23,6 +23,7 @@ The following is a human-readable summary of the license, and is not a substitut
## You are free to:
**Share** — copy and distribute the material in any medium or format for any purpose, even commercially
**Adapt** — remix, transform, and build upon the material for any purpose, even commercially
The licensor cannot revoke these freedoms as long as you follow the license terms.

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang=\"{{ meta.language-code }}\">
<html lang="{{ meta.language-code }}">
<head>
<meta charset=\"{{ meta.text-encoding }}\" />
<meta charset="{{ meta.text-encoding }}" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="{{ meta.authors }}" />
<!--<meta name="description" content="" />-->
@ -11,14 +11,9 @@
</head>
<body>
<article class="docs">
<header>
<div class="breadcrumbs">{{ meta.language }} Docs > {{ meta.project }} {{ meta.project-version }} > {{ meta.title }}</div>
</header>
{{ template.header }}
{{ document.content }}
<footer>
<p><span class="authorship">This article is part of the <a href="{{ base.relpath }}" title="{{ meta.project }} Documentation">{{ meta.project }} Documentation</a> and was written by {{ meta.authors }}.</span> <span class="contributing">Join us on GitHub to contribute your thoughts and ideas, and to suggest any necessary corrections.</span></p>
<small class="copyright">Copyright {{ meta.copyright }}. <a href="{{ base.relpath }}license-summary.html" title="License Summary"><abbr title="{{ meta.license }}">{{ meta.license-abbr }}</abbr></a>.</small>
</footer>
{{ template.footer }}
</article>
</body>
</html>

View File

@ -0,0 +1,4 @@
<footer>
<p><span class="authorship">This article is part of the <a href="{{ base.relpath }}" title="{{ meta.project }} Documentation">{{ meta.project }} Documentation</a> and was written by {{ meta.authors }}.</span> <span class="contributing">Join us on GitHub to contribute your thoughts and ideas, and to suggest any necessary corrections.</span></p>
<small class="copyright">Copyright {{ meta.copyright }}. <a href="{{ base.relpath }}license-summary.html" title="License Summary"><abbr title="{{ meta.license }}">{{ meta.license-abbr }}</abbr></a>.</small>
</footer>

View File

@ -0,0 +1,3 @@
<header>
<div class="breadcrumbs">{{ meta.language }} Docs > {{ meta.project }} {{ meta.project-version }} > {{ meta.title }}</div>
</header>