Skip to content

Commit

Permalink
feat: add inject support
Browse files Browse the repository at this point in the history
Co-authored-by: st1020 <[email protected]>
  • Loading branch information
IamPhytan and st1020 authored Oct 5, 2024
1 parent fe3b3a6 commit a6cf030
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This theme is based on Hugo theme [hugo-paper](https://github.com/nanxiaobei/hug

- Easy to use and modify
- No preset limits (This theme does not limit your content directory structure, taxonomy names, etc. It's applicable to all zola sites.)
- Inject support
- Dark mode
- Responsive design
- Social icons
Expand Down Expand Up @@ -49,6 +50,20 @@ theme = "kita"

See the `extra` section in [config.toml](https://github.com/st1020/kita/blob/main/config.toml) as a example.

## Inject support

You can easily use inject to add new features to your side without modifying the theme itself.

To use inject, you need to add some HTML files to the `templates/injects` directory.

The available inject points are: `head`, `header_nav`, `body_start`, `body_end`, `page_start`, `page_end`, `footer`, `page_info`.

For example, to load a custom script, you can add a `templates/injects/head.html` file:

```html
<script src="js-file-path-or-cdn-url.js"></script>
```

## License

[MIT License](https://github.com/st1020/kita/blob/main/LICENSE)
Expand Down
6 changes: 6 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<body class="text-black duration-200 ease-out 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%-9rem)] max-w-3xl break-words px-4 pb-16 pt-32 dark:prose-invert prose-pre:rounded-lg prose-img:rounded-lg"
>
Expand All @@ -20,5 +23,8 @@
</main>

{% include "partials/footer.html" %}

<!-- Body End inject -->
{% include "injects/body_end.html" ignore missing %}
</body>
</html>
6 changes: 6 additions & 0 deletions templates/page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% 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" %}
Expand Down Expand Up @@ -34,5 +37,8 @@ <h1 class="!my-0 pb-2.5">{{ page.title }}</h1>
{% if page.extra.comment | default(value=config.extra.comment) %}<!---->
{% include "partials/comment.html" %}<!---->
{% endif %}

<!-- Page End inject -->
{% include "injects/page_end.html" ignore missing %}
</article>
{% endblock main %}
24 changes: 14 additions & 10 deletions templates/partials/footer.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<footer class="mx-auto flex max-w-3xl flex-wrap items-center px-8 py-4 text-sm opacity-60">
<div class="mr-auto basis-full lg:basis-1/2">
{% set current_year = now() | date(format="%Y") | int %}
&copy; {% if config.extra.footer.since and config.extra.footer.since != current_year %}
{{ config.extra.footer.since }} - {{ current_year }}
{% else %}{{ current_year }}{% endif %}
<a class="link" href="{{ get_url(path=``) }}"
>{{ config.author | default(value=config.title) }}</a
>
{% set current_year = now() | date(format="%Y") | int %}<!---->
{% if config.extra.footer.since and config.extra.footer.since != current_year %}<!---->
&copy; {{ config.extra.footer.since }} - {{ current_year }}<!---->
{% else %}<!---->
&copy; {{ current_year }}<!---->
{% endif %}
<a class="link" href="{{ get_url(path=``) }}">
{{ config.author | default(value=config.title) }}
</a>
{% if config.extra.footer.license %} |<!---->
{% if config.extra.footer.license_url %}<!---->
<a class="link" href="{{ config.extra.footer.license_url }}" rel="noopener" target="_blank">
Expand All @@ -18,9 +20,11 @@
{% endif %}
</div>
<div class="flex basis-full lg:basis-1/2 lg:justify-end">
<a class="link mr-6 lg:ml-6" href="https://www.getzola.org/" rel="noopener" target="_blank"
>Powered by Zola</a
>
<a class="link mr-6 lg:ml-6" href="https://www.getzola.org/" rel="noopener" target="_blank">
Powered by Zola
</a>
<a class="link" href="https://github.com/st1020/kita" rel="noopener" target="_blank">✎ Kita</a>
</div>
<!-- Footer inject -->
{% include "injects/footer.html" ignore missing %}
</footer>
3 changes: 3 additions & 0 deletions templates/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,7 @@

<!-- Canonical -->
<link rel="canonical" href="{{ page.permalink | default(value=get_url(path=``)) }}" />

<!-- Head inject -->
{% include "injects/head.html" ignore missing %}
</head>
2 changes: 2 additions & 0 deletions templates/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
</li>
{% endfor %}
</ul>
<!-- Header Nav inject -->
{% include "injects/header_nav.html" ignore missing %}
</nav>
{% endif %}
</div>
Expand Down
2 changes: 2 additions & 0 deletions templates/partials/page_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
<span class="mx-1">&middot;</span>
<span>{{ author }}</span>
{% endif %}
<!-- Page Info inject -->
{% include "injects/page_info.html" ignore missing %}
</div>

0 comments on commit a6cf030

Please sign in to comment.