From 3af6d9131f6dfc138856d718ec96626344095ec8 Mon Sep 17 00:00:00 2001 From: Jieiku Date: Mon, 22 May 2023 23:24:44 -0700 Subject: Optimizations and Fixes --- templates/base.html | 10 +++---- templates/index.html | 28 ++++++++++++++---- templates/macros/head.html | 71 ++++++++++++++++++++++++++++++++-------------- templates/posts.html | 27 +++++++++++++++--- 4 files changed, 100 insertions(+), 36 deletions(-) (limited to 'templates') diff --git a/templates/base.html b/templates/base.html index cb8d73f..31db9bf 100644 --- a/templates/base.html +++ b/templates/base.html @@ -66,6 +66,11 @@ {%- endfor -%} {%- endif -%} + {%- if js_switcher -%} + {%- set icon_adjust=config.extra.icon_adjust | default(value="svgs adjust") -%} +
  • {%- if icon_adjust -%}{%- else -%}☀{%- endif -%}
  • + {%- endif -%} + {%- endif -%} {%- set language_count = 1 -%} {%- for language_name, language in config.languages -%} {%- set_global language_count = language_count + 1 -%} @@ -87,11 +92,6 @@ {%- endif %} {%- endif -%} - {%- if js_switcher -%} - {%- set icon_adjust=config.extra.icon_adjust | default(value="svgs adjust") -%} -
  • {%- if icon_adjust -%}{%- else -%}☀{%- endif -%}
  • - {%- endif -%} - {%- endif -%} {%- if config.build_search_index %} diff --git a/templates/index.html b/templates/index.html index 84314b1..ce224c0 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,3 +1,8 @@ +{# +This Page Shows the Posts with a short summary on the index: example.com/ +This Template can also be used as the rendering template for Sections, eg: example.com/blog/ example.com/software/ +#} + {%- extends "base.html" %} {%- block seo %} @@ -54,12 +59,25 @@ {%- endfor %} {{- macros::pagination(paginator=paginator, config=config) }} - {%- if lang == config.default_language %} - {%- set section_item = get_section(path="_index.md") %} - {%- else %} - {%- set section_item = get_section(path="_index." ~ lang ~ ".md") %} - {%- endif %} {%- if config.extra.recent | default(value=true) %} + {#- The following line is checking if the template is being used for the root or a section #} + {%- if current_path is matching("^(/[[:alpha:]][[:alpha:]])?(/page/[[:digit:]]+)?/$") %} + {%- set sec = "" %} + {%- else %} + {%- if lang == config.default_language %} + {%- set sec = current_path | trim_start_matches(pat="/") | split(pat="/page/") | slice(end=1) | join(sep="") | trim_end_matches(pat="/") %} + {%- set sec = sec ~ "/" %} + {%- else %} + {%- set sec = current_path | trim_start_matches(pat="/" ~ lang ~ "/") | split(pat="/page/") | slice(end=1) | join(sep="") | trim_end_matches(pat="/") %} + {%- set sec = sec ~ "/" %} + {%- endif %} + {%- endif %} + + {%- if lang == config.default_language %} + {%- set section_item = get_section(path=sec ~ "_index.md") %} + {%- else %} + {%- set section_item = get_section(path=sec ~ "_index." ~ lang ~ ".md") %} + {%- endif %}

    {%- if lang != config.default_language %}{{ trans(key="Recent_Posts" | safe, lang=lang) }}{% else %}Recent Posts{% endif %}

    diff --git a/templates/macros/head.html b/templates/macros/head.html index 8aa2128..5a7221c 100644 --- a/templates/macros/head.html +++ b/templates/macros/head.html @@ -1,7 +1,7 @@ {#- Theme Switcher Button to toggle between dark/light #} {%- macro theme(config) %} {%- if config.extra.js_switcher | default(value=true) %} - {%- set js_theme=config.extra.js_theme | default(value="theme.min.js") -%} + {%- set js_theme=config.extra.js_theme | default(value="js/theme.min.js") -%} {%- if js_theme %} {%- endif %} @@ -80,54 +80,81 @@ {%- if config.extra.js_bundle %} - + + + {%- if config.build_search_index %} + {%- if search_library == "elasticlunr" %} + {%- if lang != "en" %} + + + {%- endif %} + {%- endif %} + {%- endif %} {%- else %} {%- if preStyle == true %} - {%- set js_prestyle=config.extra.js_prestyle | default(value="prestyle.js") -%} + {%- set js_prestyle=config.extra.js_prestyle | default(value="js/prestyle.js") -%} {%- if js_prestyle %} {%- endif %} {%- endif %} {%- if config.extra.js_switcher | default(value=true) %} - {%- set js_theme=config.extra.js_theme | default(value="theme.min.js") -%} + {%- set js_theme=config.extra.js_theme | default(value="js/theme.min.js") -%} {%- if js_theme %} - {%- set js_themeButton=config.extra.js_themeButton | default(value="theme_button.js") -%} + {%- set js_themeButton=config.extra.js_themeButton | default(value="js/theme_button.js") -%} {%- if js_themeButton %} {%- endif %} {%- endif %} {%- endif %} - {%- set js_email=config.extra.js_email | default(value="email.js") -%} + {%- set js_email=config.extra.js_email | default(value="js/email.js") -%} {%- if js_email %} {%- if config.extra.mail_encode | default(value=true) %} {%- endif %} {%- endif %} - {%- set js_codecopy=config.extra.js_codecopy | default(value="codecopy.js") -%} + {%- set js_codecopy=config.extra.js_codecopy | default(value="js/codecopy.js") -%} {%- if js_codecopy %} {%- endif %} - {%- if config.build_search_index %} {%- if search_library == "tinysearch" %} - + {%- elif search_library == "stork" %} - - {%- else %} - - + + {%- elif config.build_search_index %} - {%- if lang != "en" %} - - + {%- set search_index_format="elasticlunr_json" -%} + {%- if config.search.index_format %} + {%- if config.search.index_format == "elasticlunr_javascript" %} + {%- set search_index_format="elasticlunr_javascript" -%} + {%- endif %} {%- endif %} + {%- set uglyurls=config.extra.uglyurls | default(value=false) -%} + {%- if search_index_format == "elasticlunr_javascript" %} + + + + {%- if uglyurls %} + + {%- else %} + + {%- endif %} + + {%- else %} + {%- endif %} + + {%- if lang != "en" %} + + + {%- endif %} + {%- endif %} {%- endif %} @@ -138,19 +165,19 @@ {#- https://github.com/KaTeX/KaTeX/tree/main/contrib/mathtex-script-type/ #} {%- if config.extra.math or page.extra.math %} -{%- set katex_bundle=config.extra.katex_bundle | default(value="katexbundle.min.js") -%} +{%- set katex_bundle=config.extra.katex_bundle | default(value="js/katexbundle.min.js") -%} {%- if katex_bundle %} {%- else %} - {%- set katex_js=config.extra.katex_js | default(value="katex.min.js") -%} + {%- set katex_js=config.extra.katex_js | default(value="js/katex.min.js") -%} {%- if katex_js %}{%- if katex_js is matching("^http[s]?://") %} {%- else %} {%- endif %}{%- endif %} - {%- set mathtex_js=config.extra.mathtex_js | default(value="mathtex-script-type.min.js") -%} + {%- set mathtex_js=config.extra.mathtex_js | default(value="js/mathtex-script-type.min.js") -%} {%- if mathtex_js %}{%- if mathtex_js is matching("^http[s]?://") %} {%- else %} @@ -158,7 +185,7 @@ {%- endif %}{%- endif %} {%- if config.extra.math_auto_render or page.extra.math_auto_render %} - {%- set katex_autorender_js=config.extra.katex_autorender_js | default(value="katex-auto-render.min.js") -%} + {%- set katex_autorender_js=config.extra.katex_autorender_js | default(value="js/katex-auto-render.min.js") -%} {%- if katex_autorender_js %} {%- if katex_autorender_js is matching("^http[s]?://") %} @@ -166,7 +193,7 @@ {%- endif %} {%- endif %} - {%- set katex_options=config.extra.katex_options | default(value="katexoptions.js") -%} + {%- set katex_options=config.extra.katex_options | default(value="js/katexoptions.js") -%} {%- if katex_options %} {%- endif %} @@ -226,7 +253,7 @@ {#- page_images: using for the blog single template page -#} {#- page_section: the blog single template page have to pass the parameter -#} {#- is_404: using for the 404.html template -#} -{%- macro seo( config, title="", title_addition="", description="", type="website", is_home=false, is_404=false, is_page=false, page_images="", page_section="", created_time="2021-07-04T07:07:00-07:00", updated_time="2021-07-04T07:07:00-07:00" ) %} +{%- macro seo( config, title="", title_addition="", description="", type="website", is_home=false, is_404=false, is_page=false, page_images="", page_section="", created_time="2023-05-15T07:07:00-07:00", updated_time="2023-05-15T07:07:00-07:00" ) %} {%- if is_404 -%} {%- else -%} diff --git a/templates/posts.html b/templates/posts.html index 92c07dc..13dc274 100644 --- a/templates/posts.html +++ b/templates/posts.html @@ -1,4 +1,7 @@ -{# This Page Shows the Posts Grouped by Year: example.com/posts/ #} +{# +This Page Shows the Posts Grouped by Year: example.com/posts/ +This Template can also be used as the rendering template for Sections, eg: example.com/blog/ example.com/software/ +#} {% extends "base.html" %} @@ -18,14 +21,30 @@ {%- endblock seo %} {%- block content %} + {#- The following line is checking if the template is being used for the posts page or a section #} + {%- if current_path is matching("^(/[[:alpha:]][[:alpha:]])?/posts/$") %} + {%- set sec = "" %} + {%- else %} + {%- set langpath = "/" %} + {%- if lang != config.default_language %} + {%- set langpath = "/" ~ lang ~ "/" %} + {%- endif %} + + {%- set sec = current_path | trim_start_matches(pat=langpath) | split(pat="/page/") | slice(end=1) | join(sep="") | trim_end_matches(pat="/") %} + {%- set sec = sec ~ "/" %} + {%- endif %} + {%- if lang == config.default_language %} - {%- set section_item = get_section(path="_index.md") %} + {%- set section_item = get_section(path=sec ~ "_index.md") %} {%- else %} - {%- set section_item = get_section(path="_index." ~ lang ~ ".md") %} + {%- set section_item = get_section(path=sec ~ "_index." ~ lang ~ ".md") %} {%- endif %}
    + {%- if section_item.title %} +

    {{ section_item.title }}

    + {%- endif %} {%- for year, posts in section_item.pages | group_by(attribute="year") %} -

    {{ year }}

    + {%- if section_item.title %}

    {{ year }}

    {%- else %}

    {{ year }}

    {%- endif %} {%- for post in posts %}

    {{ post.title }} -

    {%- endfor %} -- cgit v1.3.1