perf: give offering to lighthouse
This commit is contained in:
parent
da36eb9c94
commit
ff92b73d8f
3 changed files with 37 additions and 13 deletions
2
public/robots.txt
Normal file
2
public/robots.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
User-agent: *
|
||||||
|
Disallow:
|
|
@ -10,6 +10,7 @@ import {
|
||||||
renderSync,
|
renderSync,
|
||||||
walkSync,
|
walkSync,
|
||||||
} from "ultrahtml";
|
} from "ultrahtml";
|
||||||
|
import { querySelectorAll } from "ultrahtml/selector";
|
||||||
import { parseScript } from "esprima";
|
import { parseScript } from "esprima";
|
||||||
import config from "../mcfly.config";
|
import config from "../mcfly.config";
|
||||||
|
|
||||||
|
@ -74,7 +75,6 @@ async function insertRegistry(
|
||||||
|
|
||||||
// insert registry script to head
|
// insert registry script to head
|
||||||
if (usedCustomElements.length > 0) {
|
if (usedCustomElements.length > 0) {
|
||||||
console.log(">>> usedCustomElements", usedCustomElements);
|
|
||||||
const registryScript = await buildRegistry(usedCustomElements, type);
|
const registryScript = await buildRegistry(usedCustomElements, type);
|
||||||
walkSync(ast, (node) => {
|
walkSync(ast, (node) => {
|
||||||
if (node.type === ELEMENT_NODE && node.name === "head") {
|
if (node.type === ELEMENT_NODE && node.name === "head") {
|
||||||
|
@ -217,28 +217,30 @@ function removeComments(script: string) {
|
||||||
async function useFragments(html: string) {
|
async function useFragments(html: string) {
|
||||||
const fragmentFiles = await getFiles("html");
|
const fragmentFiles = await getFiles("html");
|
||||||
|
|
||||||
const availableFragments = fragmentFiles.map((key) => {
|
const availableFragments = fragmentFiles.reduce((acc, key) => {
|
||||||
return {
|
return {
|
||||||
key: key.replace(".html", ""),
|
...acc,
|
||||||
text: "",
|
[key.replace(".html", "")]: "",
|
||||||
};
|
};
|
||||||
});
|
}, {});
|
||||||
const ast = parse(html);
|
const ast = parse(html);
|
||||||
|
|
||||||
for (const fragment of availableFragments) {
|
// building fragment<name, text> map
|
||||||
fragment.text = await useStorage().getItem(
|
for (const key in availableFragments) {
|
||||||
"assets:components:" + fragment.key + ".html"
|
let text: string = await useStorage().getItem(
|
||||||
|
"assets:components:" + key + ".html"
|
||||||
);
|
);
|
||||||
|
availableFragments[key] = text.replace(/\n/g, "").replace(/\s+/g, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
walkSync(ast, (node) => {
|
walkSync(ast, (node) => {
|
||||||
const usedFragment = availableFragments.find(
|
const selector = Object.keys(availableFragments).find(
|
||||||
(fragment) => fragment.key === node.name
|
(name) => name === node.name
|
||||||
);
|
);
|
||||||
|
|
||||||
if (node.type === ELEMENT_NODE && !!usedFragment) {
|
if (node.type === ELEMENT_NODE && !!selector) {
|
||||||
const value = replaceSlots(usedFragment.text, node);
|
const index = node.parent.children.indexOf(node);
|
||||||
node.children.push(parse(value));
|
node.parent.children[index] = parse(availableFragments[selector]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3,5 +3,25 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>McFly: Back to the Basics. Into the Future.</title>
|
<title>McFly: Back to the Basics. Into the Future.</title>
|
||||||
<link rel="stylesheet" href="./reset.css" />
|
<link rel="stylesheet" href="./reset.css" />
|
||||||
|
<meta name="generator" content="McFly v0.0.0-super-experimental" />
|
||||||
|
<meta name="theme-color" content="#3054bf" />
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="McFly is a full-stack no-framework framework that assists developers in leveraging the web platform."
|
||||||
|
/>
|
||||||
|
<meta name="author" content="Ayo Ayco" />
|
||||||
|
<meta name="origin" content="https://mc-fly.vercel.app/" />
|
||||||
|
<!-- Open Graph data -->
|
||||||
|
<meta property="og:site_name" content="McFly" />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:url" content="https://mc-fly.vercel.app" />
|
||||||
|
<meta
|
||||||
|
property="og:title"
|
||||||
|
content="McFly: Back to the Basics. Into the Future. 😱"
|
||||||
|
/>
|
||||||
|
<meta
|
||||||
|
property="og:description"
|
||||||
|
content="McFly is a full-stack no-framework framework that assists developers in leveraging the web platform."
|
||||||
|
/>
|
||||||
<slot />
|
<slot />
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in a new issue