blob: 7d8a7a569713784a6bdf95f0916fc4430256317d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
function addMetadata() {
// Favicon
const favicon = document.createElement("link");
favicon.rel = "icon";
favicon.href = "../Logo.svg";
favicon.type = "image/svg+xml";
document.head.appendChild(favicon);
// UTF-8 charset
const charset = document.createElement("meta");
charset.setAttribute("charset", "UTF-8");
document.head.appendChild(charset);
// Viewport for mobile
const viewport = document.createElement("meta");
viewport.setAttribute("name", "viewport");
viewport.setAttribute("content", "width=device-width, initial-scale=1.0");
document.head.appendChild(viewport);
// Primary stylesheet
const css = document.createElement("link");
css.rel = "stylesheet";
css.href = "../style.css";
document.head.appendChild(css);
}
function addHeader() {
const header = document.querySelector("header");
if (!header) return;
// Back Link
const backLink = document.createElement("a");
backLink.href = "../index.html";
backLink.classList.add("header-logo-link");
backLink.textContent = "<- Back to Index";
header.appendChild(backLink);
// Right-side info container
const info = document.createElement("div");
info.classList.add("header-info");
// Title from document.title
const h1 = document.createElement("h1");
h1.textContent = document.title;
info.appendChild(h1);
// Read date from <meta property="article:published_time">
const metaDate = document.querySelector('meta[property="article:published_time"]');
if (metaDate) {
const dateString = metaDate.getAttribute("content");
const displayDate = (new Date(dateString)).toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
timeZone: "UTC"
});
const time = document.createElement("time");
time.setAttribute("datetime", dateString);
time.textContent = `Updated ${displayDate}`;
info.appendChild(time);
}
// Read class tag from <meta name="class">
const metaClass = document.querySelector('meta[name="class"]');
if (metaClass) {
const classTag = document.createElement("span");
classTag.classList.add("class-tag");
classTag.textContent = `Class: ${metaClass.getAttribute("content")}`;
info.appendChild(classTag);
}
header.appendChild(info);
const hr = document.createElement("hr");
header.appendChild(hr);
}
document.addEventListener("DOMContentLoaded", () => {
addMetadata();
addHeader();
});
|