mirror of https://github.com/tdwg/dwc.git
Improve site generator to use simple file metadata in capital words at the top of the MD file. Detect menu entry automatically based on path
This commit is contained in:
parent
3235bae8f1
commit
e5107ee40d
|
@ -1,4 +1,6 @@
|
|||
# Guidelines for contributing
|
||||
TITLE: Guidelines for contributing
|
||||
DESCRIPTION: How to contribute to Darwin Core
|
||||
|
||||
|
||||
Changes to the standard are subject to the [change policy](change_policy.html). Here's how you can contribute:
|
||||
|
||||
|
|
|
@ -15,7 +15,10 @@ import datetime as dt
|
|||
|
||||
|
||||
BASE="http://rs.gbif.org"
|
||||
|
||||
ROOT = abspath(join(os.curdir, os.pardir))
|
||||
PARAMS_MD = re.compile("^([A-Z0-9_]+)\s*\:\s*(.*)$", re.MULTILINE)
|
||||
MENU_PARAMS_HTML = re.compile("\$MENU[A-Z0-9_/]+", re.MULTILINE)
|
||||
|
||||
def traverse():
|
||||
print """building site starting at %s""" % ROOT
|
||||
|
@ -38,19 +41,35 @@ 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())
|
||||
(md, metadata)=parseMetadata(mdFile)
|
||||
print metadata
|
||||
body = mistune.markdown(md)
|
||||
path=fn[len(ROOT):]
|
||||
with codecs.open(htmlFile, 'w', 'utf-8') as f:
|
||||
f.write(buildInc(header, level))
|
||||
f.write(html)
|
||||
f.write(buildInc(footer, level))
|
||||
f.write(processMetadata(header, level, path, metadata))
|
||||
f.write(processMetadata(body, level, path, metadata))
|
||||
f.write(processMetadata(footer, level, path, metadata))
|
||||
|
||||
def buildInc(html, level):
|
||||
return html.replace("$BASE", "../"*level)\
|
||||
.replace("$DATE", str(dt.date.today()))\
|
||||
.replace("$DESCRIPTION", "")\
|
||||
.replace("$TITLE", "my title")
|
||||
def parseMetadata(mdFile):
|
||||
metadata={}
|
||||
with codecs.open(mdFile, 'r', 'utf-8') as f:
|
||||
md = f.read().strip()
|
||||
metadata["LAST_MODIFIED"]=str(dt.date.today())
|
||||
metadata["TITLE"]=""
|
||||
metadata["DESCRIPTION"]=""
|
||||
for m in PARAMS_MD.finditer(md):
|
||||
metadata[m.group(1)]=m.group(2).strip()
|
||||
md=PARAMS_MD.sub("", md)
|
||||
return (md, metadata)
|
||||
|
||||
def processMetadata(html, level, path, metadata):
|
||||
html=html.replace("$BASE", "../"*level)
|
||||
# replace menu vars
|
||||
html=html.replace("$MENU"+path.upper(), "active")
|
||||
html=MENU_PARAMS_HTML.sub("", html)
|
||||
for k, v in metadata.iteritems():
|
||||
html=html.replace("$"+k, v)
|
||||
return html
|
||||
|
||||
def anchorLinks(x):
|
||||
if x is None:
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
</div>
|
||||
<div class="col-xs-8">
|
||||
<ul class="list-inline pull-right">
|
||||
<li>Page last modified on $DATE</li>
|
||||
<li>Page last modified on $LAST_MODIFIED</li>
|
||||
<li><a href="https://github.com/tdwg/dwc/blob/gh-pages/resources.html">Edit on GitHub</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<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="DC.modified" content="$LAST_MODIFIED">
|
||||
|
||||
<meta name="dcterms.subject" content="biodiversity, standards">
|
||||
<meta name="dcterms.creator" content="Darwin Core Task Group">
|
||||
|
@ -37,27 +37,27 @@
|
|||
</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="$MENU/TERMS/INDEX"><a href="$BASEterms/index.html">Terms</a></li>
|
||||
<li class="$MENU/EXAMPLES/INDEX"><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="$MENU/CHANGE_POLICY"><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="$MENU/SIMPLE_DWC"><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="$MENU/GUIDES/TEXT/INDEX"><a href="$BASEguides/text/index.html">Text guide</a></li>
|
||||
<li class="$MENU/GUIDES/XML/INDEX"><a href="$BASEguides/xml/index.html">XML guide</a></li>
|
||||
<li class="$MENU/GUIDES/RDF/INDEX disabled"><a href="$BASEguides/rdf/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>
|
||||
<li class="$MENU/TERMS/HISTORY"><a href="$BASEterms/history.html">Term history</a></li>
|
||||
<li class="$MENU/TERMS/DECISIONS"><a href="$BASEterms/decisions.html">Term decisions</a></li>
|
||||
<li class="$MENU/TERMS/MAPPINGS"><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 class="$MENU/RESOURCES/INDEX"><a href="$BASEresources/index.html">Resources</a></li>
|
||||
<li><a href="http://github.com/tdwg/dwc">Source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
dcterms.title: Darwin Core text guide
|
||||
dcterms.description: Guidelines for implementing Darwin Core in Text files.
|
||||
dcterms.modified: 2015-01-14
|
||||
TITLE: Darwin Core text guide
|
||||
DESCRIPTION: Guidelines for implementing Darwin Core in Text files.
|
||||
LAST_MODIFIED: 2015-01-14
|
||||
|
||||
---
|
||||
|
||||
# Darwin Core text guide
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
|
|
Loading…
Reference in New Issue