-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (37 loc) · 1.01 KB
/
index.js
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
const DEFAULT_ENV_VARIABLE_NAME = "GITHUB_SHA";
const DEFAULT_HASH_BYTE_LENGTH = 4;
const htmlspecialchars = (str) => {
return str
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
};
let GITHUB_SHA = "";
module.exports = {
website: {
assets: "./assets",
js: ["plugin.js"],
},
hooks: {
page: function (page) {
page.content = `<template id="github_sha">${GITHUB_SHA}</template>${page.content}`;
return page;
},
config: function (config) {
const pluginConfig = config.pluginsConfig["github-sha"];
const environmentVariableName =
pluginConfig.environmentVariableName || DEFAULT_ENV_VARIABLE_NAME;
const hashByteLength =
pluginConfig.hashByteLength || DEFAULT_HASH_BYTE_LENGTH;
GITHUB_SHA = htmlspecialchars(
(process.env[environmentVariableName] || "").slice(
0,
2 * hashByteLength
)
);
return config;
},
},
};