mirror of
https://github.com/arfct/itty-bitty.git
synced 2026-03-11 08:54:33 +00:00
Add netlify
This commit is contained in:
parent
a6a7b37a8b
commit
910389238a
3 changed files with 60 additions and 1 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -2,4 +2,6 @@
|
|||
*.log
|
||||
*.DS_Store
|
||||
package-lock.json
|
||||
node_modules
|
||||
node_modules
|
||||
# Local Netlify folder
|
||||
.netlify
|
||||
|
|
|
|||
8
netlify.toml
Normal file
8
netlify.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[[edge_functions]]
|
||||
path = "/*/*"
|
||||
function = "index"
|
||||
|
||||
[[redirects]]
|
||||
from = "/*"
|
||||
to = "/index.html"
|
||||
status = 200
|
||||
49
netlify/edge-functions/index.js
Normal file
49
netlify/edge-functions/index.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// import { Context } from "netlify:edge";
|
||||
|
||||
|
||||
export default async (request, context) => {
|
||||
const agent = request.headers.get("user-agent");
|
||||
let url = new URL(request.url);
|
||||
let path = url.pathname;
|
||||
|
||||
if (agent.indexOf("Twitterbot") != -1 || agent.indexOf("curl") != -1 || agent.indexOf("facebookexternalhit") != -1 || agent.indexOf("Slackbot-LinkExpanding") != -1 || agent.indexOf("Discordbot") != -1) {
|
||||
let components = path.split("/");
|
||||
components.shift();
|
||||
components.pop();
|
||||
let title = decodeURIComponent(components.shift()).replace("_", " ");
|
||||
let desc = decodeURIComponent(components.shift()).replace("_", " ");
|
||||
let image = decodeURIComponent(components.join("/"));
|
||||
console.log("components", title, desc, image)
|
||||
|
||||
let content = "";
|
||||
if (title) content += `<title>${title}</title><meta property="og:title" content="${title}"/>`;
|
||||
if (desc && desc.length > 1) content += `<meta name="description" content="${desc}"/><meta property="og:description" content="${desc}"/>`;
|
||||
if (image) {
|
||||
if (image.startsWith("http")) {
|
||||
console.debug("URL Image", image)
|
||||
content += `<meta property="og:image" content="${image}"/>`;
|
||||
} else {
|
||||
image = decodeURIComponent(image)
|
||||
console.log("Emoji Image", image);
|
||||
let codepoints = [];
|
||||
for (const char of image) {
|
||||
codepoints.push(char.codePointAt(0).toString(16));
|
||||
}
|
||||
content += `<link rel="icon" type="image/png" href="https://fonts.gstatic.com/s/e/notoemoji/14.0/${codepoints.join("_")}/128.png">`
|
||||
}
|
||||
}
|
||||
console.log("content", content)
|
||||
return new Response(content, {
|
||||
headers: { "content-type": "text/html" },
|
||||
});
|
||||
} else {
|
||||
// console.log("Forward: " + "/?" + path)
|
||||
// return (context.rewrite("/?" + path))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
Loading…
Reference in a new issue