bio/template/index.html.njk
2023-10-23 17:35:42 +08:00

114 lines
2.5 KiB
Plaintext

<!DOCTYPE html>
{% macro autoreload() %}
<script>
document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] +
':35729/livereload.js?snipver=1"></' + 'script>')
</script>
{% endmacro %}
{% macro unhide_func() %}
<script>
function unhide(seed, arr) {
seed %= 1000000007;
const str_arr = [];
for (let i = 0; i < arr.length; i++) {
str_arr.push((((arr[i] - seed) % 256) + 256) % 256)
seed = seed * seed % 1000000007;
}
const ui8_arr = new Uint8Array(str_arr);
const str = new TextDecoder().decode(ui8_arr);
return str;
}
function unhide_permalink() {
let anchors = document.querySelectorAll("a[hidden_permalink][seed]")
for (let anchor of anchors) {
let arr = new Array();
for (let n of anchor.getAttribute("hidden_permalink").split(",")) {
arr.push(Number(n));
};
let seed = Number(anchor.getAttribute("seed"))
anchor.href = unhide(seed, arr);
}
}
</script>
{% endmacro %}
{% macro render_item(item) %}
{% set class_str = "item" %}
{% if item.highlight %}
{% set class_str = class_str + " " + "highlight" %}
{% endif %}
{% set href = "/#" %}
{% if item.permalink is defined and not item.hide_permalink %}
{% set href = item.permalink %}
{% endif %}
{% set misc_attr = "" %}
{% if item.hide_permalink %}
{% set misc_attr = misc_attr + " " + "hidden_permalink=\"" + item.permalink + "\"" %}
{% set misc_attr = misc_attr + " " + "seed=\"" + item.seed + "\"" %}
{% endif %}
<a class="{{ class_str }}" href="{{ href | safe }}" {{ misc_attr | safe }}>
<dl>
<dt>{{ item.name }}</dt>
{% if item.description is defined %}
<dd>{{ item.description }}</dd>
{% endif %}
</dl>
</a>
{% endmacro %}
{% macro render_section(sect) %}
<section>
<h2>{{ sect.name }}</h2>
<div class="item_container">
{% for item in sect.items %}
{{ render_item(item) }}
{% endfor %}
</div>
</section>
{% endmacro %}
<html>
<head>
{% if dev %}
{{ autoreload() }}
{% endif %}
<title>{{ name }}</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1">
<link ref="canonical" href="{{canonical_link}}" />
{{ unhide_func() }}
</head>
<style>{% include "reset.css" %}</style>
<style>{% include "style.css" %}</style>
<body onload="unhide_permalink()">
<main>
<div class="big_title">
<h1>{{ name }}</h1>
<p>{{ description }}</p>
</div>
{% for s in section %}
{{ render_section(s) }}
{% endfor %}
</main>
</body>
</html>