diff --git a/scripts/blog.py b/scripts/blog.py index d177201..36e4a36 100644 --- a/scripts/blog.py +++ b/scripts/blog.py @@ -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 😿") diff --git a/scripts/test-links.py b/scripts/test-links.py index 1fbd25e..5f142e2 100644 --- a/scripts/test-links.py +++ b/scripts/test-links.py @@ -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) diff --git a/scripts/upload.sh b/scripts/upload.sh index 1cc17cf..482106c 100644 --- a/scripts/upload.sh +++ b/scripts/upload.sh @@ -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 diff --git a/static/article.tmpl.html b/static/article.tmpl.html index d4a02c1..6383710 100644 --- a/static/article.tmpl.html +++ b/static/article.tmpl.html @@ -38,7 +38,7 @@ diff --git a/static/article_list.tmpl.html b/static/article_list.tmpl.html index 0618924..0e52252 100644 --- a/static/article_list.tmpl.html +++ b/static/article_list.tmpl.html @@ -42,7 +42,7 @@
diff --git a/static/blog_index.tmpl.html b/static/blog_index.tmpl.html index 3bc6d8f..b1939c7 100644 --- a/static/blog_index.tmpl.html +++ b/static/blog_index.tmpl.html @@ -40,7 +40,7 @@ diff --git a/static/category_list.tmpl.html b/static/category_list.tmpl.html index 1b19771..893b5a3 100644 --- a/static/category_list.tmpl.html +++ b/static/category_list.tmpl.html @@ -42,7 +42,7 @@