Add a simple markdown site generator script, see https://github.com/tdwg/dwc/issues/76

This commit is contained in:
Markus Döring 2015-01-15 22:12:50 +01:00
parent a3e456bf53
commit 1ddf683e35
6 changed files with 299 additions and 1 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.idea
.DS_Store

128
build/README.html Normal file
View File

@ -0,0 +1,128 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Darwin Core XML Guide</title>
<link href="http://rs.tdwg.org/dwc/" rel="schema.DwC">
<meta content="my title" name="DC.title">
<meta content="" name="DC.description">
<meta name="DC.modified" content="2015-01-15">
<meta name="dcterms.subject" content="biodiversity, standards">
<meta name="dcterms.creator" content="Darwin Core Task Group">
<meta name="dcterms.contributor" content="John Wieczorek (MVZ)">
<meta name="dcterms.contributor" content="Markus Döring (GBIF)">
<meta name="dcterms.contributor" content="Renato De Giovanni (CRIA)">
<meta name="dcterms.contributor" content="Tim Robertson (GBIF)">
<meta name="dcterms.contributor" content="Dave Vieglais (KUNHM)">
<meta name="dcterms.contributor" content="Peter Desmet (INBO)">
<meta name="dcterms.publisher" content="Biodiversity Information Standards (TDWG)">
<meta name="dcterms.license" content="http://creativecommons.org/licenses/by/4.0/legalcode">
<meta name="dcterms.language" content="en">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="../assets/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../assets/main.css">
<link href="http://www.tdwg.org/" rel="meta">
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index.html">Darwin Core</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="../terms/index.html">Terms</a></li>
<li><a href="../examples/index.html">Examples</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Reference <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="../change_policy.html">Change policy</a></li>
<li class="divider"></li>
<li><a href="../simple_dwc.html">Simple Darwin Core</a></li>
<li class="divider"></li>
<li><a href="../text/index.html">Text guide</a></li>
<li class="active"><a href="../xml/index.html">XML guide</a></li>
<li class="disabled"><a href="../rdf/index.html">RDF guide</a></li>
<li class="divider"></li>
<li><a href="../terms/history.html">Term history</a></li>
<li><a href="../terms/decisions.html">Term decisions</a></li>
<li><a href="../terms/mappings.html">Term mappings</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="../resources/index.html">Resources</a></li>
<li><a href="http://github.com/tdwg/dwc">Source</a></li>
</ul>
</div>
</div>
</nav>
<div class="content">
<div class="container">
<div class="page-header">
<h1>my title</h1>
</div>
<p>The build folder contains a python script to rebuild the terms index page and all resources.
It will use the current terms/dwc_normaltive.rdf and some yaml configurations inside this build folder for term definitions and order.</p>
<h2>Run the script</h2>
<p>Install the required libraries for this script with PIP once:
$ easy_install pip
$ sudo pip install -r requirements.txt</p>
<p>To run the script just run it from inside the build folder:
$ ./update_terms.py</p>
<h2>Adding new terms</h2>
<p>Simple changes for definitions should just be done in the RDF file.
In case a DwC term has been renamed, removed or added this also needs to be reflected in the following files:</p>
<h3>dc.yaml</h3>
<p>This file contains the Dublin Core terms to be used in the record level group in the right order and their DwC definitions.</p>
<h3>term_order.yaml</h3>
<p>This file contains a nested list of all DwC terms to be shown in the terms index.
The order and grouping of terms is defined here, but the definitions and other metadata is taken from the dwc_normative.rdf</p>
<h3>term_type.yaml</h3>
<p>In order to generate the postgres sql table definition the script needs to know all data types different from the default <em>text</em>.
This file contains a list of those terms with the exact data type as used in postgres.</p>
<h2>TODO</h2>
<ul>
<li>add DOI explanations</li>
</ul>
</div>
</div>
<footer class="footer">
<div class="container">
<div class="row">
<div class="col-xs-4">
<p><a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png"/></a></p>
</div>
<div class="col-xs-8">
<ul class="list-inline pull-right">
<li>Page last modified on 2015-01-15</li>
<li><a href="https://github.com/tdwg/dwc/blob/gh-pages/resources.html">Edit on GitHub</a></li>
</ul>
</div>
</div>
</div>
</footer>
<!-- Scripts -->
<script type="text/javascript" src="../assets/jquery.min.js"></script>
<script type="text/javascript" src="../assets/bootstrap.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-386033-4', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>

63
build/buildsite.py Executable file
View File

@ -0,0 +1,63 @@
#!/usr/bin/env python
'''
Install the required libraries for this script with PIP:
$ easy_install pip
$ sudo pip install -r requirements.txt
To run the script just run it from inside the build folder:
$ ./buildsite.py
'''
import re, codecs, os, mistune
from os.path import isdir, join, isfile, abspath, splitext, basename
import datetime as dt
BASE="http://rs.gbif.org"
ROOT = abspath(join(os.curdir, os.pardir))
def traverse():
print """building site starting at %s""" % ROOT
with codecs.open(join(os.curdir, "header.inc"), 'r', 'utf-8') as f:
header = f.read()
with codecs.open(join(os.curdir, "footer.inc"), 'r', 'utf-8') as f:
footer = f.read()
startinglevel = ROOT.count(os.sep)
for top, dirs, files in os.walk(ROOT):
level = top.count(os.sep) - startinglevel
print "traverse lvl %s" % level, top
# skip hidden folders
dirs[:] = [d for d in dirs if not d[0] == '.']
for file in [f for f in files if not f[0] == '.']:
(name, extension) = splitext(file)
if extension == ".md":
parse(level, join(top, name), header, footer)
def parse(level, fn, header, footer):
mdFile = fn + ".md"
htmlFile = fn + ".html"
print """PARSE %s -> %s""" % (mdFile,htmlFile)
with codecs.open(mdFile, 'r', 'utf-8') as f:
html = mistune.markdown(f.read())
with codecs.open(htmlFile, 'w', 'utf-8') as f:
f.write(buildInc(header, level))
f.write(html)
f.write(buildInc(footer, level))
def buildInc(html, level):
return html.replace("$BASE", "../"*level)\
.replace("$DATE", str(dt.date.today()))\
.replace("$DESCRIPTION", "")\
.replace("$TITLE", "my title")
def anchorLinks(x):
if x is None:
return x
return re.sub('(https?://\S+[a-zA-Z0-9/_-])', "<a href='\\1'>\\1</a>", x)
if __name__ == "__main__":
traverse()

34
build/footer.inc Normal file
View File

@ -0,0 +1,34 @@
</div>
</div>
<footer class="footer">
<div class="container">
<div class="row">
<div class="col-xs-4">
<p><a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png"/></a></p>
</div>
<div class="col-xs-8">
<ul class="list-inline pull-right">
<li>Page last modified on $DATE</li>
<li><a href="https://github.com/tdwg/dwc/blob/gh-pages/resources.html">Edit on GitHub</a></li>
</ul>
</div>
</div>
</div>
</footer>
<!-- Scripts -->
<script type="text/javascript" src="../assets/jquery.min.js"></script>
<script type="text/javascript" src="../assets/bootstrap.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-386033-4', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>

71
build/header.inc Normal file
View File

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Darwin Core XML Guide</title>
<link href="http://rs.tdwg.org/dwc/" rel="schema.DwC">
<meta content="$TITLE" name="DC.title">
<meta content="$DESCRIPTION" name="DC.description">
<meta name="DC.modified" content="$DATE">
<meta name="dcterms.subject" content="biodiversity, standards">
<meta name="dcterms.creator" content="Darwin Core Task Group">
<meta name="dcterms.contributor" content="John Wieczorek (MVZ)">
<meta name="dcterms.contributor" content="Markus Döring (GBIF)">
<meta name="dcterms.contributor" content="Renato De Giovanni (CRIA)">
<meta name="dcterms.contributor" content="Tim Robertson (GBIF)">
<meta name="dcterms.contributor" content="Dave Vieglais (KUNHM)">
<meta name="dcterms.contributor" content="Peter Desmet (INBO)">
<meta name="dcterms.publisher" content="Biodiversity Information Standards (TDWG)">
<meta name="dcterms.license" content="http://creativecommons.org/licenses/by/4.0/legalcode">
<meta name="dcterms.language" content="en">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="$BASEassets/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="$BASEassets/main.css">
<link href="http://www.tdwg.org/" rel="meta">
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="$BASEindex.html">Darwin Core</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="$BASEterms/index.html">Terms</a></li>
<li><a href="$BASEexamples/index.html">Examples</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Reference <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="$BASEchange_policy.html">Change policy</a></li>
<li class="divider"></li>
<li><a href="$BASEsimple_dwc.html">Simple Darwin Core</a></li>
<li class="divider"></li>
<li><a href="$BASEtext/index.html">Text guide</a></li>
<li class="active"><a href="$BASExml/index.html">XML guide</a></li>
<li class="disabled"><a href="$BASErdf/index.html">RDF guide</a></li>
<li class="divider"></li>
<li><a href="$BASEterms/history.html">Term history</a></li>
<li><a href="$BASEterms/decisions.html">Term decisions</a></li>
<li><a href="$BASEterms/mappings.html">Term mappings</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="$BASEresources/index.html">Resources</a></li>
<li><a href="http://github.com/tdwg/dwc">Source</a></li>
</ul>
</div>
</div>
</nav>
<div class="content">
<div class="container">
<div class="page-header">
<h1>$TITLE</h1>
</div>

View File

@ -1,3 +1,4 @@
Cheetah==2.4.4
rdflib==4.1.2
PyYAML==3.11
PyYAML==3.11
mistune