mirror of
https://github.com/cupcakearmy/blaze.git
synced 2024-12-22 16:26:26 +00:00
commit
460bdc1e24
5
dist/index.html
vendored
5
dist/index.html
vendored
@ -11,6 +11,7 @@
|
|||||||
<title>Blaze</title>
|
<title>Blaze</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@ -46,10 +47,10 @@
|
|||||||
</section>
|
</section>
|
||||||
<footer>
|
<footer>
|
||||||
<a href="/info">What is this?</a>
|
<a href="/info">What is this?</a>
|
||||||
<a href="https://www.buymeacoffee.com/dannyspina">Buy me a beer</a>
|
<a href="https://www.buymeacoffee.com/dannyspina">Buy me a 🍺</a>
|
||||||
</footer>
|
</footer>
|
||||||
<script>
|
<script>
|
||||||
const DEV = 0,
|
const DEV = "%NODE_ENV%" !== "production",
|
||||||
e = DEV ? "http://localhost:8888" : "https://blaze.cyclic.app",
|
e = DEV ? "http://localhost:8888" : "https://blaze.cyclic.app",
|
||||||
t = document.querySelector("button"),
|
t = document.querySelector("button"),
|
||||||
c = document.querySelector("input");
|
c = document.querySelector("input");
|
||||||
|
7
dist/info.html
vendored
7
dist/info.html
vendored
@ -8,7 +8,12 @@
|
|||||||
name="description"
|
name="description"
|
||||||
content="Discover Blaze, the search engine for seamless browsing in any connection condition. Minimize bandwidth with minimalist page rendering. Enhance your browsing experience."
|
content="Discover Blaze, the search engine for seamless browsing in any connection condition. Minimize bandwidth with minimalist page rendering. Enhance your browsing experience."
|
||||||
/>
|
/>
|
||||||
<title>Blaze</title>
|
<title>Blaze - info</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>What is this site?</h2>
|
<h2>What is this site?</h2>
|
||||||
|
42
dist/info_not_blazed.html
vendored
Normal file
42
dist/info_not_blazed.html
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Blaze - ooops</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Why are some pages unable to be blazed?</h1>
|
||||||
|
<p>
|
||||||
|
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.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
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.
|
||||||
|
</p>
|
||||||
|
<h2>But the page was an article/blog post!</h2>
|
||||||
|
<p>
|
||||||
|
In such cases, it is possible that Blaze has detected a false positive. It
|
||||||
|
would be greatly appreciated
|
||||||
|
<a href="mailto:support.blaze@dannyspina.com"
|
||||||
|
>if you could provide the URL of the page</a
|
||||||
|
>
|
||||||
|
where you encountered this message while expecting it to work. This
|
||||||
|
information will help me reduce false positives for other users as well.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a href="/">Back to blaze</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
24
dist/not_blazed.html
vendored
Normal file
24
dist/not_blazed.html
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Blaze</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
text-align: center;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100dvh;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>This page can not be blazed... Sorry!</h2>
|
||||||
|
<a href="/ooops">Why does not work?</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
46
index.ts
46
index.ts
@ -4,7 +4,7 @@ import { JSDOM } from "jsdom";
|
|||||||
import got from "got";
|
import got from "got";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
import fetch from 'node-fetch'
|
import fetch from "node-fetch";
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@ -21,10 +21,10 @@ app.get("/", async (req, res) => {
|
|||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
res.sendFile(path.join(__dirname + "/dist/index.html"));
|
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) {
|
if (!key) {
|
||||||
throw new Error("No brave key found");
|
throw new Error("No brave key found");
|
||||||
@ -32,42 +32,46 @@ app.get("/", async (req, res) => {
|
|||||||
|
|
||||||
fetch(`${searchEngine}?q=${query}`, {
|
fetch(`${searchEngine}?q=${query}`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "*/*",
|
Accept: "*/*",
|
||||||
"Accept-Encoding": "gzip, deflate, br",
|
"Accept-Encoding": "gzip, deflate, br",
|
||||||
"X-Subscription-Token": key,
|
"X-Subscription-Token": key,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((page) => {
|
.then((page) => {
|
||||||
page.json().then(response => {
|
page.json().then((response) => {
|
||||||
const results: any[] = []
|
const results: any[] = [];
|
||||||
|
const url = process.env.DEV_MODE
|
||||||
|
? "http://localhost:8888/blazed"
|
||||||
|
: "https://blaze.cyclic.app/blazed";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
response.web.results.forEach(result => {
|
response.web.results.forEach((result) => {
|
||||||
results.push(`
|
results.push(`
|
||||||
<div>
|
<div>
|
||||||
|
<a href="${url}?url=${result.url}">
|
||||||
<h2>${result.title}</h2>
|
<h2>${result.title}</h2>
|
||||||
<span>${result.meta_url.hostname}</span>
|
|
||||||
<a href="https://blaze.cyclic.app/blazed?url=${result.url}">
|
|
||||||
<p>${result.description}</p>
|
|
||||||
</a>
|
</a>
|
||||||
|
<span>${result.meta_url.hostname}</span>
|
||||||
|
<p>${result.description}</p>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
`);
|
`);
|
||||||
})
|
});
|
||||||
res.send(`<html>
|
res.send(`<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
<title>Blaze The Page</title>
|
<title>Blaze - ${query}</title>
|
||||||
<style>
|
<style>
|
||||||
|
body {font-family:sans-serif}
|
||||||
h2 {margin-bottom:0}
|
h2 {margin-bottom:0}
|
||||||
span {font-size: .9rem}
|
span {font-size:.9rem}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
${results.join("")}
|
${results.join("")}
|
||||||
</body>
|
</body>
|
||||||
</html>`);
|
</html>`);
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -75,14 +79,14 @@ app.get("/", async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get("/blazed", (req, res) => {
|
app.get("/blazed", (req, res) => {
|
||||||
const pageToBlaze = req.query.url as string
|
const pageToBlaze = req.query.url as string;
|
||||||
|
|
||||||
got(pageToBlaze)
|
got(pageToBlaze)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const dom = new JSDOM(response.body);
|
const dom = new JSDOM(response.body);
|
||||||
|
|
||||||
if (!isProbablyReaderable(dom.window.document)) {
|
if (!isProbablyReaderable(dom.window.document)) {
|
||||||
res.send("This page can not be blazed... Sorry!")
|
res.sendFile(path.join(__dirname + "/dist/not_blazed.html"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,11 +103,15 @@ got(pageToBlaze)
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
app.get("/info", (_, res) => {
|
app.get("/info", (_, res) => {
|
||||||
res.sendFile(path.join(__dirname + "/dist/info.html"));
|
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, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Got request`);
|
console.log(`Got request`);
|
||||||
|
Loading…
Reference in New Issue
Block a user