meta
This commit is contained in:
parent
445a797c9a
commit
c82ac0397d
4 changed files with 45 additions and 13 deletions
|
@ -1,8 +1,5 @@
|
||||||
<article>
|
<div class="article">
|
||||||
<h1><a href="{{ base_path }}/{{ year }}/{{ slug }}.html">{{ title }}</a></h1>
|
<h1><a href="{{ base_path }}/{{ year }}/{{ slug }}.html">{{ title }}</a></h1>
|
||||||
<p class="meta">{{ category_label}}<span>{{ date }}</span></p>
|
<p class="meta">{{ category_label}}<span>{{ friendly_date }}</span></p>
|
||||||
<p class="summary">{{ summary }}</p>
|
<p class="summary">{{ summary }}</p>
|
||||||
<div>
|
|
||||||
<a class="more" href="{{ base_path }}/{{ year }}/{{ slug }}.html">Lire la suite...</a>
|
|
||||||
</div>
|
</div>
|
||||||
</article>
|
|
|
@ -1,5 +1,5 @@
|
||||||
<article>
|
<div class="article">
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
<p class="meta">{{ category_label}}<span>{{ date }}</span></p>
|
<p class="meta">{{ category_label}}<span>{{ friendly_date }}</span></p>
|
||||||
{{ content }}
|
{{ content }}
|
||||||
</article>
|
</div>
|
26
makesite.py
26
makesite.py
|
@ -36,6 +36,10 @@ import json
|
||||||
import datetime
|
import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
import locale
|
||||||
|
|
||||||
|
# set user locale
|
||||||
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
|
||||||
def fread(filename):
|
def fread(filename):
|
||||||
"""Read file and close the file."""
|
"""Read file and close the file."""
|
||||||
|
@ -87,6 +91,7 @@ def slugify(value):
|
||||||
value = re.sub('[^\w\s-]', '', value).strip().lower()
|
value = re.sub('[^\w\s-]', '', value).strip().lower()
|
||||||
return re.sub('[-\s]+', '-', value)
|
return re.sub('[-\s]+', '-', value)
|
||||||
|
|
||||||
|
|
||||||
def read_content(filename):
|
def read_content(filename):
|
||||||
"""Read content and metadata from file into a dictionary."""
|
"""Read content and metadata from file into a dictionary."""
|
||||||
# Read file content.
|
# Read file content.
|
||||||
|
@ -127,6 +132,17 @@ def read_content(filename):
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
def clean_html_tag(text):
|
||||||
|
"""Remove HTML tags."""
|
||||||
|
while True:
|
||||||
|
original_text = text
|
||||||
|
text = re.sub('<\w+.*?>', '', text)
|
||||||
|
text = re.sub('<\/\w+>', '', text)
|
||||||
|
if original_text == text:
|
||||||
|
break
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def render(template, **params):
|
def render(template, **params):
|
||||||
"""Replace placeholders in template with values from params."""
|
"""Replace placeholders in template with values from params."""
|
||||||
return re.sub(r'{{\s*([^}\s]+)\s*}}',
|
return re.sub(r'{{\s*([^}\s]+)\s*}}',
|
||||||
|
@ -171,6 +187,11 @@ def make_pages(src, dst, layout, **params):
|
||||||
return sorted(items, key=lambda x: x['date'], reverse=True)
|
return sorted(items, key=lambda x: x['date'], reverse=True)
|
||||||
|
|
||||||
|
|
||||||
|
def get_friendly_date(date_str):
|
||||||
|
dt = datetime.datetime.strptime(date_str, '%Y-%m-%d')
|
||||||
|
return dt.strftime('%d %b %Y')
|
||||||
|
|
||||||
|
|
||||||
def make_posts(src, src_pattern, dst, layout, category_layout, **params):
|
def make_posts(src, src_pattern, dst, layout, category_layout, **params):
|
||||||
"""Generate posts from posts directory."""
|
"""Generate posts from posts directory."""
|
||||||
items = []
|
items = []
|
||||||
|
@ -182,6 +203,7 @@ def make_posts(src, src_pattern, dst, layout, category_layout, **params):
|
||||||
page_params = dict(params, **content)
|
page_params = dict(params, **content)
|
||||||
page_params['banner'] =' '
|
page_params['banner'] =' '
|
||||||
page_params['date_path'] = page_params['date'].replace('-', '/')
|
page_params['date_path'] = page_params['date'].replace('-', '/')
|
||||||
|
page_params['friendly_date'] = get_friendly_date(page_params['date'])
|
||||||
page_params['year'] = page_params['date'].split('-')[0]
|
page_params['year'] = page_params['date'].split('-')[0]
|
||||||
|
|
||||||
# categories
|
# categories
|
||||||
|
@ -201,11 +223,11 @@ def make_posts(src, src_pattern, dst, layout, category_layout, **params):
|
||||||
|
|
||||||
summary_index = page_params['content'].find('<!-- more')
|
summary_index = page_params['content'].find('<!-- more')
|
||||||
if summary_index > 0:
|
if summary_index > 0:
|
||||||
content['summary'] = render(page_params['content'][:summary_index], **page_params)
|
content['summary'] = clean_html_tag(render(page_params['content'][:summary_index], **page_params))
|
||||||
|
|
||||||
content['year'] = page_params['year']
|
content['year'] = page_params['year']
|
||||||
content['category_label'] = page_params['category_label']
|
content['category_label'] = page_params['category_label']
|
||||||
|
content['friendly_date'] = page_params['friendly_date']
|
||||||
items.append(content)
|
items.append(content)
|
||||||
|
|
||||||
# TODO DEBUG
|
# TODO DEBUG
|
||||||
|
|
|
@ -141,6 +141,19 @@ a:hover, a:active {
|
||||||
padding-right: 20px;
|
padding-right: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.summary {
|
||||||
|
margin-top: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article > h1 {
|
||||||
|
margin-bottom: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta {
|
||||||
|
margin-top: 0px;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
.meta > span {
|
.meta > span {
|
||||||
display: inline;
|
display: inline;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
|
Loading…
Add table
Reference in a new issue