bio/template/index.html.njk

130 lines
2.7 KiB
Plaintext
Raw Normal View History

2023-07-13 06:11:06 +00:00
<!DOCTYPE html>
{% macro autoreload() %}
<script>
var uuid = "";
function handle_uuid(u) {
if (uuid.length === 0) {
uuid = u;
return;
}
if (uuid != u ) {
location.reload();
}
}
function autoreload() {
fetch("/uuid")
.then(res => res.text())
.then(handle_uuid);
}
setInterval(autoreload, 1000);
</script>
{% endmacro %}
2023-07-14 07:56:29 +00:00
{% 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 %}
2023-07-13 06:11:06 +00:00
2023-07-14 03:10:19 +00:00
{% macro render_item(item) %}
{% set class_str = "item" %}
{% if item.highlight %}
{% set class_str = class_str + " " + "highlight" %}
{% endif %}
2023-07-14 07:56:29 +00:00
{% set href = "/#" %}
{% if item.permalink is defined and not item.hide_permalink %}
2023-07-14 03:10:19 +00:00
{% set href = item.permalink %}
2023-07-13 06:11:06 +00:00
{% endif %}
2023-07-14 03:10:19 +00:00
2023-07-14 07:56:29 +00:00
{% 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 }}>
2023-07-14 03:10:19 +00:00
<dl>
<dt>{{ item.name }}</dt>
{% if item.description is defined %}
<dd>{{ item.description }}</dd>
{% endif %}
</dl>
</a>
2023-07-13 06:11:06 +00:00
{% endmacro %}
2023-07-14 03:10:19 +00:00
{% macro render_section(sect) %}
2023-07-13 06:11:06 +00:00
<section>
<h2>{{ sect.name }}</h2>
<div class="item_container">
{% for item in sect.items %}
2023-07-14 03:10:19 +00:00
{{ render_item(item) }}
2023-07-13 06:11:06 +00:00
{% 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}}" />
2023-07-14 07:56:29 +00:00
{{ unhide_func() }}
2023-07-13 06:11:06 +00:00
</head>
<style>{% include "reset.css" %}</style>
<style>{% include "style.css" %}</style>
2023-07-14 07:56:29 +00:00
<body onload="unhide_permalink()">
2023-07-13 06:11:06 +00:00
<main>
2023-07-14 03:10:19 +00:00
<div class="big_title">
2023-07-13 06:11:06 +00:00
<h1>{{ name }}</h1>
<p>{{ description }}</p>
</div>
2023-07-14 03:10:19 +00:00
{% for s in section %}
{{ render_section(s) }}
{% endfor %}
2023-07-13 06:11:06 +00:00
</main>
</body>
</html>