mirror of
https://github.com/cupcakearmy/blaze.git
synced 2024-12-22 08:16:26 +00:00
Add marker to links saved in cache
This commit is contained in:
parent
5e65c17c4b
commit
c7ea6a4442
0
dist/styles/serp.css
vendored
Normal file
0
dist/styles/serp.css
vendored
Normal file
16
index.ts
16
index.ts
@ -12,6 +12,7 @@ import { minify } from "html-minifier";
|
|||||||
import {
|
import {
|
||||||
blazeFunctionality,
|
blazeFunctionality,
|
||||||
blazeUrl,
|
blazeUrl,
|
||||||
|
highlightBlazedLinks,
|
||||||
injectBlazeToPageLinks,
|
injectBlazeToPageLinks,
|
||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
import etag from "etag";
|
import etag from "etag";
|
||||||
@ -86,9 +87,9 @@ app.get("/", async (req, res) => {
|
|||||||
const results = data.web.results.map(
|
const results = data.web.results.map(
|
||||||
(result: any) => `
|
(result: any) => `
|
||||||
<article>
|
<article>
|
||||||
<a href="${blazeUrl}/blazed?url=${result.url}">
|
<h2><a href="${blazeUrl}/blazed?url=${result.url}">
|
||||||
<h2>${result.title}</h2>
|
${result.title}
|
||||||
</a>
|
</a></h2>
|
||||||
<span>${result.meta_url.hostname}</span>
|
<span>${result.meta_url.hostname}</span>
|
||||||
<p>${result.description}</p>
|
<p>${result.description}</p>
|
||||||
</article>
|
</article>
|
||||||
@ -122,7 +123,12 @@ app.get("/", async (req, res) => {
|
|||||||
${results.join("")}
|
${results.join("")}
|
||||||
<script>
|
<script>
|
||||||
${blazeFunctionality}
|
${blazeFunctionality}
|
||||||
|
${highlightBlazedLinks}
|
||||||
|
|
||||||
blazeFunctionality('${blazeUrl}')
|
blazeFunctionality('${blazeUrl}')
|
||||||
|
const links = document.querySelectorAll('a')
|
||||||
|
highlightBlazedLinks(links)
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -261,6 +267,10 @@ app.get("/blazed", async (req, res) => {
|
|||||||
const url = "${blazeUrl}"
|
const url = "${blazeUrl}"
|
||||||
const currentUrl = "${req.query.url}"
|
const currentUrl = "${req.query.url}"
|
||||||
injectBlazeToPageLinks(url, currentUrl)
|
injectBlazeToPageLinks(url, currentUrl)
|
||||||
|
|
||||||
|
${highlightBlazedLinks}
|
||||||
|
const links = document.querySelectorAll('a')
|
||||||
|
highlightBlazedLinks(links)
|
||||||
</script>
|
</script>
|
||||||
</body></html>
|
</body></html>
|
||||||
`;
|
`;
|
||||||
|
21
utils.ts
21
utils.ts
@ -31,3 +31,24 @@ export function blazeFunctionality(blazeUrl: string) {
|
|||||||
location.href = blazeUrl + "?q=" + encodeURIComponent(c!.value);
|
location.href = blazeUrl + "?q=" + encodeURIComponent(c!.value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function highlightBlazedLinks(links: HTMLLinkElement[]) {
|
||||||
|
links.forEach((link) => {
|
||||||
|
if (
|
||||||
|
!link.href ||
|
||||||
|
link.href === "http://localhost:8888/" ||
|
||||||
|
link.href === "https://blaze.cyclic.app"
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(link.href);
|
||||||
|
caches.open("blaze").then((cache) => {
|
||||||
|
cache.match(url.href).then((response) => {
|
||||||
|
if (response) {
|
||||||
|
link.innerHTML = `${link.textContent} ⚡`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user