Repository navigation
Expand file tree
/
Copy pathnext.config.js
More file actions
103 lines (95 loc) · 2.9 KB
/
Copy pathnext.config.js
File metadata and controls
103 lines (95 loc) · 2.9 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* eslint-disable @typescript-eslint/no-require-imports */
/** @type {import('next').NextConfig} */
const securityHeaders = [
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "X-Frame-Options", value: "DENY" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
{ key: "X-DNS-Prefetch-Control", value: "on" },
{
key: "Permissions-Policy",
value: "camera=(), microphone=(), geolocation=(), interest-cohort=()",
},
{
key: "Strict-Transport-Security",
value: "max-age=63072000; includeSubDomains; preload",
},
];
const fs = require("node:fs");
const path = require("node:path");
const { execFileSync } = require("node:child_process");
function getGitDate(...filePaths) {
try {
const out = execFileSync("git", ["log", "-1", "--format=%cs", "--", ...filePaths], {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
}).trim();
return out || null;
} catch {
return null;
}
}
function getSitemapDates() {
const dates = {};
try {
let isShallow = false;
try {
isShallow =
execFileSync("git", ["rev-parse", "--is-shallow-repository"], {
stdio: ["ignore", "pipe", "ignore"],
encoding: "utf8",
}).trim() === "true";
if (isShallow) {
try {
execFileSync("git", ["fetch", "--unshallow"], {
stdio: ["ignore", "ignore", "ignore"],
});
isShallow =
execFileSync("git", ["rev-parse", "--is-shallow-repository"], {
stdio: ["ignore", "pipe", "ignore"],
encoding: "utf8",
}).trim() === "true";
} catch {
// Unshallow failed (e.g. offline)
}
}
} catch {
return dates;
}
if (isShallow) {
// In a shallow clone that cannot be unshallowed, do not query git log
// because every file would falsely inherit the latest commit date.
return dates;
}
const homeDate = getGitDate("app/page.tsx", "lib/tools.ts");
if (homeDate) dates["/"] = homeDate;
const toolsDir = "app/(tools)";
if (fs.existsSync(toolsDir)) {
for (const entry of fs.readdirSync(toolsDir, { withFileTypes: true })) {
if (entry.isDirectory() && fs.existsSync(path.join(toolsDir, entry.name, "page.tsx"))) {
const date = getGitDate(path.join(toolsDir, entry.name));
if (date) dates[`/${entry.name}`] = date;
}
}
}
} catch {
// Filesystem or unexpected error; return dates found so far
}
return dates;
}
const nextConfig = {
reactStrictMode: true,
// Inlined at build time for the WebSite JSON-LD dateModified and sitemap lastModified.
env: {
BUILD_DATE: new Date().toISOString().slice(0, 10),
SITEMAP_DATES: JSON.stringify(getSitemapDates()),
},
async headers() {
return [
{
source: "/:path*",
headers: securityHeaders,
},
];
},
};
module.exports = nextConfig;