Skip to content

Commit

Permalink
[using themes]
Browse files Browse the repository at this point in the history
  • Loading branch information
wangbyby committed Mar 2, 2025
1 parent 64f06e6 commit b211b9b
Show file tree
Hide file tree
Showing 29 changed files with 1,204 additions and 33 deletions.
5 changes: 5 additions & 0 deletions templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "index.html" %}
{% block main %}
<h1 class="absolute inset-x-8 bottom-20 top-0 flex items-center justify-center text-6xl">{{
macros::tr(key="error_not_found", lk=lang, td=g_trans_data) }}</h1>
{% endblock main %}
31 changes: 31 additions & 0 deletions templates/archive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "index.html" %}
{% block main %}
{%- if g_profile is defined %}
{% include "partials/profile.html" %}
{%- else %}
<h1 class="mb-16">{{ page.title }}</h1>
{%- endif %}
{% set section = get_section(path=page.extra.section) %}

{% for year, posts in section.pages | group_by(attribute="year") %}
<h2>{{ year }} <sup class="opacity-60">{{ posts | length }}</sup></h2>

<div class="not-prose pl-6">
<ul>
{% for post in posts %}
<li>
<div class="my-2 flex items-center justify-between">
<a class="secondary-link" href="{{ post.permalink | escape_xml | safe }}">{{ post.title }}</a>
{%- set date_format_archive = config.extra.languages[lang].date_format_archive | default(value="%m-%d") %}
<time class="font-mono text-sm max-md:flex-none opacity-80" datetime="{{ post.date | date(format=`%+`) }}">{%
if config.extra.languages[lang].locale %}{{ post.date | date(format=date_format_archive,
locale=config.extra.languages[lang].locale) }}{%
else %}{{ post.date | date(format=date_format_archive) }}{% endif %}</time>
</div>
</li>
{% endfor %}
</ul>
</div>

{% endfor %}
{% endblock main %}
79 changes: 60 additions & 19 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,63 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ config.title }}</title>
{% import "macros.html" as macros %}
{%- set g_trans_data = load_data(path="i18n.json", format="json") %}
{%- if page.extra.profile %}
{%- set profile_username = page.extra.profile %}
{%- elif section.extra.profile %}
{%- set profile_username = section.extra.profile %}
{%- elif taxonomy.name is defined and taxonomy.name == "authors" and term.name is defined %}
{%- set profile_username = term.name %}
{%- endif %}
{%- if profile_username is defined %}
{%- if config.extra.profiles[profile_username] %}
{%- set g_profile = config.extra.profiles[profile_username] %}
{%- else %}
{%- set g_profile = load_data(literal='{"name": "'~profile_username~'"}', format="json") %}
{%- endif %}
{%- endif %}
{%- if page.extra.cover.width is defined or page.extra.cover.height is defined %}
{%- set g_image_data = load_data(literal='{"width": '~page.extra.cover.width~
',"height": '~page.extra.cover.height~'}', format="json") %}
{%- elif page.extra.cover.image %}
{%- set g_image_path = page.extra.cover.image %}
{%- set g_image_data = get_image_metadata(path=g_image_path, allow_missing=true) %}
{%- endif %}
{%- set g_is_article = page.date is defined or page.updated is defined %}
{%- set g_html_lang = config.extra.languages[lang].language_code | default(value=lang) %}
{#- -#}
<!doctype html>
<html class="not-ready overflow-y-scroll lg:text-base" lang="{{ g_html_lang | escape_xml | safe }}">

<head prefix="og: https://ogp.me/ns#{%
if g_profile is defined %} profile: https://ogp.me/ns/profile#{%
elif g_is_article %} article: https://ogp.me/ns/article#{%
endif %}">
{%- include "partials/head.html" %}
{%- include "partials/head_res.html" %}
<!-- Head inject -->
{% include "injects/head.html" ignore missing %}
</head>
<body>
<h1>{{ config.title }}</h1>
<p>{{ config.description }}</p>

<h2>最新文章</h2>
<ul>
{% for page in section.pages %}
<li>
<a href="{{ page.permalink }}">{{ page.title }}</a>
<span>{{ page.date }}</span>
</li>
{% endfor %}
</ul>
<body class="text-black duration-200 ease-out bg-[var(--bg)] dark:text-white">
{% include "partials/header.html" %}
<!-- Body Start inject -->
{% include "injects/body_start.html" ignore missing %}
<main class="prose prose-neutral relative mx-auto min-h-[calc(100%-4rem)]
max-w-3xl break-words px-4 pb-12 pt-28 lg:pt-32 dark:prose-invert prose-pre:rounded-lg prose-img:rounded-lg">
{%- if config.build_search_index %}
{% include "partials/search.html" %}
{%- endif %}
{%- block main %}
<!-- Profile -->
{%- if g_profile is defined and (paginator is undefined or paginator.current_index == 1) %}
{% include "partials/profile.html" %}
{%- endif %}
{% include "partials/page_list.html" %}
{%- endblock main %}
</main>
{% include "partials/footer.html" %}
{% include "partials/body_res.html" %}
<!-- Body End inject -->
{% include "injects/body_end.html" ignore missing %}
</body>
</html>

</html>
34 changes: 34 additions & 0 deletions templates/macros.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{%- macro get_social_icon(icon) -%}
{%- set path = "icons/" ~ icon ~ ".svg" -%}
{%- set meta = get_image_metadata(path=path, allow_missing=true) -%}
{%- if meta -%}
{{- get_url(path=path) -}}
{%- else -%}
{{- "https://cdn.jsdelivr.net/npm/simple-icons/icons/" ~ icon ~ ".svg" -}}
{%- endif -%}
{%- endmacro get_social_icon -%}

{%- macro get_profile_name(username) -%}
{%- if config.extra.profiles[username] -%}
{%- set profile_data = config.extra.profiles[username] -%}
{%- if profile_data.languages[lang].name -%}
{%- set profile_name = profile_data.languages[lang].name -%}
{%- elif profile_data.name -%}
{%- set profile_name = profile_data.name -%}
{%- else -%}
{%- set profile_name = username -%}
{%- endif -%}
{%- else -%}
{%- set profile_name = username -%}
{%- endif -%}
{%- if profile_name -%}
{{- profile_name -}}
{%- endif -%}
{%- endmacro get_profile_name -%}

{%- macro tr(key, lk, td) -%}
{%- if td[key][lk] %}{{ td[key][lk] }}
{%- elif td[key]["en"] %}{{ td[key]["en"] }}
{%- else %}{{ td[key][lk] }}
{%- endif %}
{%- endmacro tr -%}
55 changes: 41 additions & 14 deletions templates/page.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ page.title }}</title>
</head>
<body>
<h1>{{ page.title }}</h1>
<p>发布日期: {{ page.date }}</p>
<hr>
{{ page.content | safe }}
</body>
</html>
{% extends "index.html" %}
{% block main %}
<article>
<!-- Page Start inject -->
{% include "injects/page_start.html" ignore missing %}

<header class="mb-16">
<h1 class="!my-0 pb-2.5">{{ page.title }}</h1>
{% include "partials/page_info.html" %}
</header>

{%- if page.extra.cover.image %}
<figure class="mb-12 mt-0">
<img
class="h-auto w-full rounded-lg"
src="{{ get_url(path=page.extra.cover.image) }}"
{% if page.extra.cover.alt is defined %}alt="{{ page.extra.cover.alt | escape_xml | safe }}"{% endif %}
{% if g_image_data.width is defined %}width="{{ g_image_data.width | int }}"{% endif %}
{% if g_image_data.height is defined %}height="{{ g_image_data.height | int }}"{% endif %}
/>
</figure>
{%- endif %}

<!-- TOC -->
{% include "partials/toc.html" %}

<!-- Content -->
<section>{{ page.content | safe }}</section>
<hr />
<!-- Post Taxonomies -->
{% include "partials/post_taxonomies.html" %}
<!-- Post Nav -->
{% include "partials/post_navigation.html" %}
{%- if page.extra.comment | default(value=config.extra.comment) %}
<!-- Comment -->
{% include "partials/comment.html" %}
{%- endif %}
<!-- Page End inject -->
{% include "injects/page_end.html" ignore missing %}
</article>
{% endblock main %}
19 changes: 19 additions & 0 deletions templates/pages.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "index.html" %}
{% block main %}
{%- if g_profile is defined %}
{% include "partials/profile.html" %}
{%- endif %}
<article>
{%- if g_profile is undefined %}
<header class="mb-16">
<h1 class="!my-0">{{ page.title }}</h1>
</header>
{%- endif %}

<section>{{ page.content | safe }}</section>
{%- if config.extra.post_navigation is defined %}
<!-- Post Nav -->
{% include "partials/post_navigation.html" %}
{%- endif %}
</article>
{% endblock main %}
30 changes: 30 additions & 0 deletions templates/partials/body_res.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{%- if not config.extra.disable_javascript %}
{%- if page.extra.mermaid | default(value=config.extra.mermaid) %}
<!-- Mermaid -->
{% include "partials/mermaid.html" %}
{%- endif %}
{%- if config.extra.goatcounter.endpoint %}
{%- if config.extra.goatcounter.src %}
{%- set goatcounter_src = config.extra.goatcounter.src %}
{%- elif config.extra.use_cdn %}
{%- set goatcounter_src = "//gc.zgo.at/count.js" %}
{%- else %}
{%- set goatcounter_src = get_url(path=`js/gc.min.js`, cachebust=true) %}
{%- endif %}
<!-- GoatCounter -->
<script>window.linkita.initGoatCounterAnalytics({
src: "{{ goatcounter_src | escape_xml | safe }}",
endpoint: "{{ config.extra.goatcounter.endpoint | escape_xml | safe }}"
});</script>
{%- if config.extra.goatcounter.noscript_prefix is defined and current_path is defined %}
<noscript><img src="{{ config.extra.goatcounter.endpoint | escape_xml | safe }}?p={{
config.extra.goatcounter.noscript_prefix ~ current_path | urlencode | safe }}" alt=""></noscript>
{%- endif %}
{%- endif %}
{%- if config.extra.vercel_analytics.src %}
<!-- Vercel Web Analytics -->
<script>window.linkita.initVercelAnalytics({
src: "{{ config.extra.vercel_analytics.src | escape_xml | safe }}"
});</script>
{%- endif %}
{%- endif %}
20 changes: 20 additions & 0 deletions templates/partials/comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% if config.extra.giscus.repo and not config.extra.disable_javascript %}
<div class="giscus mt-12"></div>
<script
src="https://giscus.app/client.js"
data-repo="{{ config.extra.giscus.repo | escape_xml | safe }}"
data-repo-id="{{ config.extra.giscus.repo_id | escape_xml | safe }}"
data-category="{{ config.extra.giscus.category | escape_xml | safe }}"
data-category-id="{{ config.extra.giscus.category_id | escape_xml | safe }}"
data-mapping="{{ config.extra.giscus.mapping | default(value=`pathname`) | escape_xml | safe }}"
data-strict="{{ config.extra.giscus.strict | default(value=`1`) | int }}"
data-reactions-enabled="{{ config.extra.giscus.reactions_enabled | default(value=`0`) | int }}"
data-emit-metadata="{{ config.extra.giscus.emit_metadata | default(value=`0`) | int }}"
data-input-position="{{ config.extra.giscus.input_position | default(value=`top`) | escape_xml | safe }}"
data-theme="{{ config.extra.giscus.theme | default(value=`light`) | escape_xml | safe }}"
data-lang="{{ config.extra.giscus.lang | default(value=`en`) | escape_xml | safe }}"
data-loading="{{ config.extra.giscus.loading | default(value=`lazy`) | escape_xml | safe }}"
crossorigin="anonymous"
async
></script>
{% endif %}
44 changes: 44 additions & 0 deletions templates/partials/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<footer class="mx-auto flex lg:mt-5 max-w-3xl flex-wrap items-center px-8 py-3 text-sm opacity-60">
<div class="mr-auto basis-full lg:basis-1/2">
{%- set base_url_lang = get_url(path="", lang=lang) %}
{%- if config.extra.footer.copyright %}
{%- set copyright = config.extra.footer.copyright | replace(from=`$BASE_URL`, to=base_url_lang) %}
{%- if config.extra.footer.license_url %}
{%- set license_url = config.extra.footer.license_url | replace(from=`$BASE_URL`, to=base_url_lang) %}
{%- set copyright = copyright | replace(from=`$LICENSE_URL`, to=license_url) %}
{%- endif %}
{%- else %}
{%- if config.author %}
{%- set author_name = macros::get_profile_name(username=config.author) %}
{%- set copyright = "&copy; $YEAR " ~ author_name %}
{%- else %}
{%- set copyright = "&copy; $YEAR" %}
{%- endif %}
{%- if config.extra.footer.license_url %}
{%- set license_url = config.extra.footer.license_url | replace(from=`$BASE_URL`, to=base_url_lang) %}
{%- set copyright = "[" ~ copyright ~ "](" ~ license_url ~ ')' %}
{%- endif %}
{%- endif %}
{%- set current_year = now() | date(format="%Y") | int %}
{%- if config.extra.footer.since and config.extra.footer.since != current_year %}
{%- set copyright_years = '<time datetime="' ~ config.extra.footer.since ~ '">' ~
config.extra.footer.since ~ '</time> - <time datetime="' ~ current_year ~ '">' ~
current_year ~ '</time>' %}
{%- else %}
{%- set copyright_years = '<time datetime="' ~ current_year ~ '">' ~ current_year ~ '</time>' %}
{%- endif %}
{%- set copyright = copyright | replace(from=`$YEAR`, to=copyright_years) %}
{{ copyright | markdown(inline=true) | safe }}
</div>
<div class="flex basis-full lg:basis-1/2 lg:justify-end">
<span class="mr-6 lg:ml-6">
{{ macros::tr(key="footer_powered_by", lk=lang, td=g_trans_data) }} <a
class="link" href="https://www.getzola.org/" target="_blank">{{
macros::tr(key="footer_generator_name", lk=lang, td=g_trans_data) }}</a>
</span>
<a class="link" href="https://www.getzola.org/themes/linkita/" target="_blank">&#9998; {{
macros::tr(key="footer_theme_name", lk=lang, td=g_trans_data) }}</a>
</div>
<!-- Footer inject -->
{% include "injects/footer.html" ignore missing %}
</footer>
Loading

0 comments on commit b211b9b

Please sign in to comment.