Compare commits
No commits in common. "23f8fcefe56523a3b25c1d68c4f96f385d6340ef" and "302ec0b7646d7b7a2ed6897b8156268075c0a43b" have entirely different histories.
23f8fcefe5
...
302ec0b764
@ -63,10 +63,6 @@ JINJA_ENV = jinja2.Environment(
|
||||
autoescape=jinja2.select_autoescape()
|
||||
)
|
||||
|
||||
WATCH = True
|
||||
if os.getenv('WATCH_AND_REBUILD', '1') == '0':
|
||||
WATCH = False
|
||||
|
||||
def update_statics():
|
||||
global ARTICLE_TEMPLATE
|
||||
ARTICLE_TEMPLATE = JINJA_ENV.get_template(ARTICLE_TEMPLATE_NAME)
|
||||
@ -126,7 +122,6 @@ def slugify(title):
|
||||
slug = unidecode(title).lower()
|
||||
slug = SLUG_REMOVE_RE.sub('', slug)
|
||||
slug = SLUG_HYPHENATE_RE.sub('-', slug)
|
||||
slug = slug.strip('-')
|
||||
|
||||
return slug.strip()
|
||||
|
||||
@ -172,7 +167,7 @@ def get_out_path(front_matter):
|
||||
|
||||
out_path = os.path.join(str(front_matter['date'].year), front_matter['slug'])
|
||||
if front_matter.get('lang', LANG_PRIORITY[0]) != LANG_PRIORITY[0]:
|
||||
out_path = os.path.join(front_matter['lang'], str(front_matter['date'].year), front_matter['slug'])
|
||||
out_path = os.path.join(str(front_matter['date'].year), front_matter['lang'], front_matter['slug'])
|
||||
return out_path
|
||||
|
||||
|
||||
@ -296,6 +291,15 @@ def summarize(doc):
|
||||
for child in summary.children:
|
||||
result.append(child)
|
||||
|
||||
# Update summary links and hrefs
|
||||
for v in result.find_all('video') + result.find_all('image'):
|
||||
if 'src' in v.attrs and ':' not in v['src']:
|
||||
v['src'] = '/blog/' + v['src'].lstrip('/')
|
||||
|
||||
for v in result.find_all('a'):
|
||||
if 'href' in v.attrs and ':' not in v['href']:
|
||||
v['href'] = '/blog/' + v['href'].lstrip('/')
|
||||
|
||||
return result
|
||||
|
||||
def render_index(docs, dest_top):
|
||||
@ -384,7 +388,7 @@ def render_categories(docs, dest_top):
|
||||
result = CATEGORY_LIST_TEMPLATE.render(
|
||||
posts=posts,
|
||||
)
|
||||
path = os.path.join(dest_top, "tags", tag.replace('/', '_'), "index.html")
|
||||
path = os.path.join(dest_top, "tags", tag, "index.html")
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, 'wt') as f:
|
||||
f.write(result)
|
||||
@ -516,10 +520,6 @@ def main(source_top, dest_top):
|
||||
docs = regen_all(source_top, dest_top)
|
||||
logging.info("Initial load completed in {:.2f}s".format(time.time() - t0))
|
||||
|
||||
if not WATCH:
|
||||
logging.info("Build completed in {:.2f}s".format(time.time() - t0))
|
||||
return 0
|
||||
|
||||
## Updating
|
||||
for event in notifier.event_gen(yield_nones=False):
|
||||
(ev, types, directory, file) = event
|
||||
@ -573,12 +573,11 @@ def main(source_top, dest_top):
|
||||
docs[filepath] = (doc, front_matter, out_path)
|
||||
doc_full_path = os.path.join(dest_top, out_path)
|
||||
print("Updated: {}.html".format(doc_full_path))
|
||||
os.makedirs(os.path.dirname(doc_full_path + '/index.html'), exist_ok=True)
|
||||
os.makedirs(os.path.dirname(doc_full_path), exist_ok=True)
|
||||
# print("==", doc_full_path)
|
||||
with open(doc_full_path + '/index.html', 'wt') as f:
|
||||
try:
|
||||
render_article(doc, front_matter, f, out_path)
|
||||
render_archive(docs, dest_top)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
logging.error("Rendering failed 😿")
|
||||
|
@ -3,7 +3,6 @@
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import urllib.parse
|
||||
|
||||
from bs4 import BeautifulSoup as bs4
|
||||
|
||||
@ -20,32 +19,25 @@ def main(files_top):
|
||||
print("\r{} files".format(len(found_files)), end='', flush=True)
|
||||
|
||||
print()
|
||||
found_broken = 0
|
||||
found_broken = False
|
||||
for fpath in tqdm(found_files):
|
||||
with open(fpath) as f:
|
||||
tree = bs4(f.read(), features='lxml', parser='html5')
|
||||
|
||||
for tag, attr in [('a', 'href'), ('img', 'src'), ('audio', 'src'), ('video', 'src')]:
|
||||
for link in tree.find_all(tag):
|
||||
if attr not in link.attrs:
|
||||
continue
|
||||
link.attrs[attr] = link.attrs[attr].split('#')[0]
|
||||
if not link.attrs[attr]:
|
||||
continue
|
||||
if ':' in link[attr]:
|
||||
continue
|
||||
if link[attr].startswith('/'):
|
||||
target = os.path.join(os.path.abspath(files_top), urllib.parse.unquote(link[attr].lstrip('/')))
|
||||
else:
|
||||
target = os.path.join(os.path.dirname(fpath), urllib.parse.unquote(link[attr]))
|
||||
if os.path.isdir(target):
|
||||
pass
|
||||
elif not os.path.exists(target):
|
||||
print("[{}] -[ error ]-> {} | {}".format(fpath, target, link[attr]))
|
||||
found_broken += 1
|
||||
for link in tree.find_all('a'):
|
||||
if 'href' not in link.attrs:
|
||||
continue
|
||||
if ':' in link['href']:
|
||||
continue
|
||||
if link['href'].startswith('/'):
|
||||
target = link['href'] # TODO: Find a better way to model the root
|
||||
else:
|
||||
target = os.path.join(os.path.dirname(fpath), link['href'])
|
||||
if os.path.isdir(target):
|
||||
pass
|
||||
elif not os.path.exists(target):
|
||||
print("[{}] -[ error ]-> {} | {}".format(fpath, target, link['href']))
|
||||
|
||||
if found_broken:
|
||||
print(f"Found {found_broken} broken links")
|
||||
exit(1)
|
||||
else:
|
||||
exit(0)
|
||||
|
@ -13,15 +13,11 @@ cd ../scripts
|
||||
rm -Rf ../_gen/notes
|
||||
WATCH_AND_REBUILD=0 python3 generate.py ~/.logs/brain ../_gen/notes
|
||||
|
||||
rm -Rf ../_gen/blog
|
||||
WATCH_AND_REBUILD=0 python3 blog.py ~/cloud/nextcloud/blog/posts/ ../_gen/blog
|
||||
|
||||
# Upload notes
|
||||
cd ../_gen
|
||||
rsync -HPaz static/ --delete-after --exclude='*.html' root@codigoparallevar.com:/mnt/vols/misc/codigoparallevar/static/
|
||||
rsync -HPaz notes/ --delete-after --exclude='xapian' --exclude='*.sqlite3' root@codigoparallevar.com:/mnt/vols/misc/codigoparallevar/notes/
|
||||
rsync -HPaz notes/db.sqlite3 root@codigoparallevar.com:/mnt/vols/misc/codigoparallevar-api/
|
||||
rsync -HPaz blog/ --delete-after --exclude='xapian' --exclude='*.sqlite3' root@codigoparallevar.com:/mnt/vols/misc/codigoparallevar/blog/
|
||||
|
||||
# Restart API server
|
||||
ssh root@codigoparallevar.com docker restart notes-api-server
|
||||
|
@ -38,7 +38,7 @@
|
||||
</time>
|
||||
<ul class="post-tags">
|
||||
{% for post_tag in post_tags %}
|
||||
<li class="post-tag"><a href="{{ base_path }}/tags/{{ post_tag |urlencode|replace('/', '_') }}/"</a>{{ post_tag }}</a></li>
|
||||
<li class="post-tag"><a href="{{ base_path }}/tags/{{ post_tag }}/"</a>{{ post_tag }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -42,7 +42,7 @@
|
||||
<div class="post-metadata">
|
||||
<ul class="post-tags">
|
||||
{% for post_tag in post.post_tags %}
|
||||
<li class="post-tag"><a href="../tags/{{ post_tag |urlencode|replace('/', '_') }}/">{{ post_tag }}</a></li>
|
||||
<li class="post-tag"><a href="../tags/{{ post_tag }}/"</a>{{ post_tag }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -40,7 +40,7 @@
|
||||
</time>
|
||||
<ul class="post-tags">
|
||||
{% for post_tag in post.post_tags %}
|
||||
<li class="post-tag"><a href="tags/{{ post_tag |urlencode|replace('/', '_') }}/"</a>{{ post_tag }}</a></li>
|
||||
<li class="post-tag"><a href="tags/{{ post_tag }}/"</a>{{ post_tag }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -42,7 +42,7 @@
|
||||
<div class="post-metadata">
|
||||
<ul class="post-tags">
|
||||
{% for post_tag in post.post_tags %}
|
||||
<li class="post-tag"><a href="../../tags/{{ post_tag |urlencode|replace('/', '_') }}/">{{ post_tag }}</a></li>
|
||||
<li class="post-tag"><a href="../../tags/{{ post_tag }}/"</a>{{ post_tag }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user