Add years to writings and sort based on them.
This commit is contained in:
@@ -53,7 +53,7 @@ def extract_markdown_title(filename):
|
||||
if filename.endswith('.md'):
|
||||
return os.path.basename(filename)[:-3]
|
||||
|
||||
def extract_markdown_abstract(filename):
|
||||
def extract_markdown_yaml(filename):
|
||||
state = 0
|
||||
with open(filename) as f:
|
||||
for line in f:
|
||||
@@ -66,7 +66,11 @@ def extract_markdown_abstract(filename):
|
||||
if y is None:
|
||||
return None
|
||||
else:
|
||||
return y.get('abstract').strip().replace('\n', ' ')
|
||||
if 'abstract' in y:
|
||||
y['abstract'] = y.get('abstract').strip().replace('\n', ' ')
|
||||
if 'lastupdated' in y:
|
||||
y['lastupdated'] = int(y.get('lastupdated'))
|
||||
return y
|
||||
else:
|
||||
yaml_block += line
|
||||
|
||||
@@ -103,17 +107,22 @@ def markdown_to_html(input_file, output_dir):
|
||||
for page in pages:
|
||||
url, path = page
|
||||
ptitle = extract_markdown_title(path)
|
||||
pabstract = extract_markdown_abstract(path)
|
||||
pages_new.append((ptitle, pabstract, url, path))
|
||||
pyaml = extract_markdown_yaml(path)
|
||||
pages_new.append((ptitle, pyaml, url, path))
|
||||
|
||||
pages_new.append(('Potators', 'Do not look.', '/potator/', '/potator/'))
|
||||
pages_new.append(('Potators', {'abstract': 'Do not look.', 'lastupdated': 2011}, '/potator/', '/potator/'))
|
||||
|
||||
pages_new.sort()
|
||||
pages_new.sort(key=lambda p: (10000 - (p[1].get('lastupdated') or 10000), p[0]))
|
||||
md = ''
|
||||
for page in pages_new:
|
||||
ptitle, pabstract, url, _ = page
|
||||
if pabstract is None:
|
||||
ptitle, pyaml, url, _ = page
|
||||
if pyaml is None or pyaml.get('abstract') is None:
|
||||
pabstract = '(No description)'
|
||||
else:
|
||||
pabstract = pyaml['abstract']
|
||||
lu = pyaml.get('lastupdated')
|
||||
if lu is not None:
|
||||
pabstract += ' ({})'.format(lu)
|
||||
md += '[{}]({})\n ~ {}\n\n'.format(ptitle, url, pabstract)
|
||||
|
||||
content = pandoc_stdin(input_base.replace('SPECIAL:ARTICLES', md))
|
||||
|
||||
Reference in New Issue
Block a user