Add support for ugly urls to allow for offline sites with no webserver

This commit is contained in:
Che 2022-07-23 04:13:15 -04:00
parent d9d1698c5d
commit c50ccf9fb1
4 changed files with 41 additions and 12 deletions

View file

@ -11,4 +11,11 @@ highlight_theme = "base16-ocean-light"
logo = "https://easydocs.codeandmedia.com/logo.svg" logo = "https://easydocs.codeandmedia.com/logo.svg"
release = "https://api.github.com/repos/getzola/zola/releases/latest" release = "https://api.github.com/repos/getzola/zola/releases/latest"
favicon = "https://www.getzola.org/favicon.ico" favicon = "https://www.getzola.org/favicon.ico"
easydocs_logo_always_clickable = false easydocs_logo_always_clickable = false
# For use with offline sites. If set to true template links are generated with the full path indcluding index.html
# Insired by Abridge theme https://www.getzola.org/themes/abridge/
# Notes:
# - Also requries the base URL to be set to the local folder where the site is stored eg. base_url = /home/user/mysite/public/
# - This is not portable and only works with a specific local folder
easydocs_uglyurls = false

View file

@ -29,9 +29,13 @@
</script> </script>
{% endif -%} {% endif -%}
<main> <main>
{% if not config.extra.easydocs_uglyurls -%}
{% set _ugly_url = "" -%}
{% else %}
{% set _ugly_url = "index.html" -%}
{% endif -%}
{% block nav -%} {%- block nav -%}
<nav> <nav>
{% if config.extra.logo -%} {% if config.extra.logo -%}
{% set _logo = config.extra.logo -%} {% set _logo = config.extra.logo -%}
@ -41,13 +45,13 @@
{% if current_path == "/" and not config.extra.easydocs_logo_always_clickable -%} {% if current_path == "/" and not config.extra.easydocs_logo_always_clickable -%}
<img src="{{ _logo | safe }}" alt="logo"/> <img src="{{ _logo | safe }}" alt="logo"/>
{% else -%} {% else -%}
<a href="{{ config.base_url }}"> <a href="{{ config.base_url }}{{ _ugly_url }}">
<img src="{{ _logo | safe }}" alt="logo"/> <img src="{{ _logo | safe }}" alt="logo"/>
</a> </a>
{% endif -%} {% endif -%}
{% else -%} {% else -%}
<h1><a href="{{ config.base_url }}">{{ config.title }}</a></h1> <h1><a href="{{ config.base_url }}{{ _ugly_url }}">{{ config.title }}</a></h1>
{% endif -%} {% endif -%}
{% if config.extra.release -%} {% if config.extra.release -%}
@ -69,7 +73,7 @@
<ul class="subtree"> <ul class="subtree">
{% for page in subsection.pages -%} {% for page in subsection.pages -%}
<li {% if current_path == page.path %}class="active"{% endif %}> <li {% if current_path == page.path %}class="active"{% endif %}>
<a href="{{ page.permalink | safe }}">{{ page.title }}</a> <a href="{{ page.permalink | safe }}{{ _ugly_url }}">{{ page.title }}</a>
</li> </li>
{% if page.toc -%} {% if page.toc -%}
@ -90,12 +94,19 @@
{% if header_count > 4 -%} {% if header_count > 4 -%}
<ul id="toc"> <ul id="toc">
{% for h2 in page.toc -%} {% for h2 in page.toc -%}
<li><a href="{{ h2.permalink | safe }}">{{ h2.title }}</a> <li><a href="
{{ h2.permalink | safe }}{{ _ugly_url }}">{{ h2.title }}</a>
{% if h2.children -%} {% if h2.children -%}
<ul> <ul>
{% for h3 in h2.children -%} {% for h3 in h2.children -%}
<li> <li>
<a href="{{ h3.permalink | safe }}">{{ h3.title }}</a> <a href="
{{ h3.permalink | safe }}{{ _ugly_url }}">{{ h3.title }}</a>
</li> </li>
{% endfor -%} {% endfor -%}
</ul> </ul>

View file

@ -1,14 +1,19 @@
<h2>Table of Contents</h2> <h2>Table of Contents</h2>
{% if not config.extra.easydocs_uglyurls -%}
{% set _ugly_url = "" -%}
{% else %}
{% set _ugly_url = "index.html" -%}
{% endif -%}
{% if section.subsections -%} {% if section.subsections -%}
<ul> <ul>
{% for subsec in section.subsections -%} {% for subsec in section.subsections -%}
{% set sec_ = get_section(path=subsec) -%} {% set sec_ = get_section(path=subsec) -%}
<li> <li>
<a href="{{ sec_.permalink | safe }}">{{ sec_.title }}</a> <a href="{{ sec_.permalink | safe }}{{ _ugly_url }}">{{ sec_.title }}</a>
{% if sec_.pages -%} {% if sec_.pages -%}
<ul> <ul>
{% for page_ in sec_.pages -%} {% for page_ in sec_.pages -%}
<li><a href="{{ page_.permalink | safe }}">{{ page_.title }}</a></li> <li><a href="{{ page_.permalink | safe }}{{ _ugly_url }}">{{ page_.title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif -%} {% endif -%}

View file

@ -3,6 +3,12 @@
{% block title %} {{ config.title }} | {{ section.title }} {% endblock title %} {% block title %} {{ config.title }} | {{ section.title }} {% endblock title %}
{% block content %} {% block content %}
{% if not config.extra.easydocs_uglyurls -%}
{% set _ugly_url = "" -%}
{% else %}
{% set _ugly_url = "index.html" -%}
{% endif -%}
{% if section.word_count > 0 -%} {% if section.word_count > 0 -%}
{{ section.content | safe }} {{ section.content | safe }}
{% else -%} {% else -%}
@ -13,7 +19,7 @@
<ul> <ul>
{% for subsec in section.subsections -%} {% for subsec in section.subsections -%}
{% set sec_ = get_section(path=subsec) -%} {% set sec_ = get_section(path=subsec) -%}
<li><a href="{{ sec_.permalink | safe }}">{{ sec_.title }}</a></li> <li><a href="{{ sec_.permalink | safe }}{{ _ugly_url }}">{{ sec_.title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif -%} {% endif -%}
@ -22,7 +28,7 @@
<ul> <ul>
{% if section.pages -%} {% if section.pages -%}
{% for page in section.pages -%} {% for page in section.pages -%}
<li><a href="{{ page.permalink | safe }}">{{ page.title }}</a></li> <li><a href="{{ page.permalink | safe }}{{ _ugly_url }}">{{ page.title }}</a></li>
{% endfor -%} {% endfor -%}
{% else -%} {% else -%}
<li>No pages</li> <li>No pages</li>