From b8ad4078deb004d4e9bf23353873029589b05a85 Mon Sep 17 00:00:00 2001 From: Danny Spina Date: Tue, 20 Jun 2023 09:32:07 +0200 Subject: [PATCH 1/2] Add some content --- index.ts | 78 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/index.ts b/index.ts index 8b47cbb..c6332b2 100644 --- a/index.ts +++ b/index.ts @@ -4,7 +4,7 @@ import { JSDOM } from "jsdom"; import got from "got"; import path from "path"; import { fileURLToPath } from "url"; -import fetch from 'node-fetch' +import fetch from "node-fetch"; import "dotenv/config"; const app = express(); @@ -21,10 +21,10 @@ app.get("/", async (req, res) => { if (!query) { res.sendFile(path.join(__dirname + "/dist/index.html")); - return + return; } - const key = process.env.CYCLIC_BRAVE_KEY + const key = process.env.CYCLIC_BRAVE_KEY; if (!key) { throw new Error("No brave key found"); @@ -32,42 +32,46 @@ app.get("/", async (req, res) => { fetch(`${searchEngine}?q=${query}`, { headers: { - "Accept": "*/*", + Accept: "*/*", "Accept-Encoding": "gzip, deflate, br", "X-Subscription-Token": key, }, }) .then((page) => { - page.json().then(response => { - const results: any[] = [] + page.json().then((response) => { + const results: any[] = []; + const url = process.env.DEV_MODE + ? "http://localhost:8888/blazed" + : "https://blaze.cyclic.app/blazed"; // @ts-ignore - response.web.results.forEach(result => { + response.web.results.forEach((result) => { results.push(`
+

${result.title}

+
${result.meta_url.hostname} -

${result.description}

-

`); - }) + }); res.send(` - Blaze The Page + Blaze - ${query} ${results.join("")} `); - }) + }); }) .catch((err) => { console.log(err); @@ -75,35 +79,39 @@ app.get("/", async (req, res) => { }); app.get("/blazed", (req, res) => { -const pageToBlaze = req.query.url as string - -got(pageToBlaze) - .then((response) => { - const dom = new JSDOM(response.body); + const pageToBlaze = req.query.url as string; - if (!isProbablyReaderable(dom.window.document)) { - res.send("This page can not be blazed... Sorry!") - return; - } + got(pageToBlaze) + .then((response) => { + const dom = new JSDOM(response.body); - let reader = new Readability(dom.window.document); - let article = reader.parse(); + if (!isProbablyReaderable(dom.window.document)) { + res.sendFile(path.join(__dirname + "/dist/not_blazed.html")); + return; + } - if (!article) { - res.send("Something went wrong"); - return; - } + let reader = new Readability(dom.window.document); + let article = reader.parse(); - res.send(article.content); - }) - .catch((err) => { - console.log(err); - }); -}) + if (!article) { + res.send("Something went wrong"); + return; + } + + res.send(article.content); + }) + .catch((err) => { + console.log(err); + }); +}); app.get("/info", (_, res) => { res.sendFile(path.join(__dirname + "/dist/info.html")); -}) +}); + +app.get("/ooops", (_, res) => { + res.sendFile(path.join(__dirname + "/dist/info_not_blazed.html")); +}); app.listen(port, () => { console.log(`Got request`); From 21b5847c3b50cb3524af3168ee3d310ddff95b95 Mon Sep 17 00:00:00 2001 From: Danny Spina Date: Tue, 20 Jun 2023 09:32:16 +0200 Subject: [PATCH 2/2] Add some content --- dist/index.html | 5 +++-- dist/info.html | 7 ++++++- dist/info_not_blazed.html | 42 +++++++++++++++++++++++++++++++++++++++ dist/not_blazed.html | 24 ++++++++++++++++++++++ 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 dist/info_not_blazed.html create mode 100644 dist/not_blazed.html diff --git a/dist/index.html b/dist/index.html index 1a99e13..9d64dc2 100644 --- a/dist/index.html +++ b/dist/index.html @@ -11,6 +11,7 @@ Blaze

What is this site?

diff --git a/dist/info_not_blazed.html b/dist/info_not_blazed.html new file mode 100644 index 0000000..fb7c192 --- /dev/null +++ b/dist/info_not_blazed.html @@ -0,0 +1,42 @@ + + + + + + Blaze - ooops + + + +

Why are some pages unable to be blazed?

+

+ The purpose of Blaze is to allow users to navigate the web and access the + content they need even in challenging connection situations or when + seeking a minimalistic resource and data usage. However, generating a + "pure HTML only content page" from every page is not always possible. +

+

+ Blaze utilizes the same library that Firefox uses to generate the "read + mode" of a page, providing a distraction-free and minimalist version for + better content absorption. However, this library is primarily designed for + reading purposes. Therefore, when navigating to websites like Amazon that + do not contain readable content, Blaze cannot generate a minimalistic + version of the website. +

+

But the page was an article/blog post!

+

+ In such cases, it is possible that Blaze has detected a false positive. It + would be greatly appreciated + if you could provide the URL of the page + where you encountered this message while expecting it to work. This + information will help me reduce false positives for other users as well. +

+ + Back to blaze + + diff --git a/dist/not_blazed.html b/dist/not_blazed.html new file mode 100644 index 0000000..c0497c4 --- /dev/null +++ b/dist/not_blazed.html @@ -0,0 +1,24 @@ + + + + + + Blaze + + + +

This page can not be blazed... Sorry!

+ Why does not work? + +