fix: lock and format
This commit is contained in:
parent
30977d1357
commit
593b4cde4a
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
|||||||
- name: Set up Node.js
|
- name: Set up Node.js
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: "20"
|
node-version: '20'
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
|
2
.github/workflows/format-check.yml
vendored
2
.github/workflows/format-check.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
|||||||
- name: Set up Node.js
|
- name: Set up Node.js
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: "20"
|
node-version: '20'
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import StackOverflow from "./stackoverflow";
|
import StackOverflow from './stackoverflow';
|
||||||
import Readability from "./readability";
|
import Readability from './readability';
|
||||||
import SearX from "./searx";
|
import SearX from './searx';
|
||||||
|
|
||||||
export { StackOverflow, Readability, SearX };
|
export { StackOverflow, Readability, SearX };
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { Readability as OReadability } from "@mozilla/readability";
|
import { Readability as OReadability } from '@mozilla/readability';
|
||||||
import { EngineParseError } from "@txtdot/sdk/dist/types/errors";
|
import { EngineParseError } from '@txtdot/sdk/dist/types/errors';
|
||||||
|
|
||||||
import { Engine } from "@txtdot/sdk";
|
import { Engine } from '@txtdot/sdk';
|
||||||
|
|
||||||
const Readability = new Engine(
|
const Readability = new Engine(
|
||||||
"Readability",
|
'Readability',
|
||||||
"Engine for parsing content with Readability",
|
'Engine for parsing content with Readability',
|
||||||
["*"]
|
['*']
|
||||||
);
|
);
|
||||||
|
|
||||||
Readability.route("*path", async (input, ro) => {
|
Readability.route('*path', async (input, ro) => {
|
||||||
const reader = new OReadability(input.parseDom().window.document);
|
const reader = new OReadability(input.parseDom().window.document);
|
||||||
const parsed = reader.parse();
|
const parsed = reader.parse();
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Engine } from "@txtdot/sdk";
|
import { Engine } from '@txtdot/sdk';
|
||||||
import { HandlerInput, Route } from "@txtdot/sdk/dist/types/handler";
|
import { HandlerInput, Route } from '@txtdot/sdk/dist/types/handler';
|
||||||
|
|
||||||
const SearX = new Engine("SearX", "Engine for searching with 'SearXNG'", [
|
const SearX = new Engine('SearX', "Engine for searching with 'SearXNG'", [
|
||||||
"searx.*",
|
'searx.*',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
async function search(
|
async function search(
|
||||||
@ -11,26 +11,26 @@ async function search(
|
|||||||
) {
|
) {
|
||||||
const document = input.parseDom().window.document;
|
const document = input.parseDom().window.document;
|
||||||
const search = ro.q.search;
|
const search = ro.q.search;
|
||||||
const page = parseInt(ro.q.pageno || "1");
|
const page = parseInt(ro.q.pageno || '1');
|
||||||
|
|
||||||
const page_footer = `${
|
const page_footer = `${
|
||||||
page !== 1
|
page !== 1
|
||||||
? `<a href="${ro.reverse({ search, pageno: page - 1 })}">Previous </a>|`
|
? `<a href="${ro.reverse({ search, pageno: page - 1 })}">Previous </a>|`
|
||||||
: ""
|
: ''
|
||||||
}<a href="${ro.reverse({ search, pageno: page + 1 })}"> Next</a>`;
|
}<a href="${ro.reverse({ search, pageno: page + 1 })}"> Next</a>`;
|
||||||
|
|
||||||
const articles = Array.from(document.querySelectorAll(".result"));
|
const articles = Array.from(document.querySelectorAll('.result'));
|
||||||
const articles_parsed = articles.map((a) => {
|
const articles_parsed = articles.map((a) => {
|
||||||
const parsed = {
|
const parsed = {
|
||||||
url:
|
url:
|
||||||
(a.getElementsByClassName("url_wrapper")[0] as HTMLAnchorElement)
|
(a.getElementsByClassName('url_wrapper')[0] as HTMLAnchorElement)
|
||||||
.href || "",
|
.href || '',
|
||||||
title:
|
title:
|
||||||
(a.getElementsByTagName("h3")[0] as HTMLHeadingElement).textContent ||
|
(a.getElementsByTagName('h3')[0] as HTMLHeadingElement).textContent ||
|
||||||
"",
|
'',
|
||||||
content:
|
content:
|
||||||
(a.getElementsByClassName("content")[0] as HTMLDivElement)
|
(a.getElementsByClassName('content')[0] as HTMLDivElement)
|
||||||
.textContent || "",
|
.textContent || '',
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -41,8 +41,8 @@ async function search(
|
|||||||
|
|
||||||
const content = `${articles_parsed
|
const content = `${articles_parsed
|
||||||
.map((a) => a.html)
|
.map((a) => a.html)
|
||||||
.join("")}${page_footer}`;
|
.join('')}${page_footer}`;
|
||||||
const textContent = articles_parsed.map((a) => a.text).join("");
|
const textContent = articles_parsed.map((a) => a.text).join('');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content,
|
content,
|
||||||
@ -52,7 +52,7 @@ async function search(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
SearX.route("/search?q=:search&pageno=:pageno", search);
|
SearX.route('/search?q=:search&pageno=:pageno', search);
|
||||||
SearX.route("/search?q=:search", search);
|
SearX.route('/search?q=:search', search);
|
||||||
|
|
||||||
export default SearX;
|
export default SearX;
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
import { Engine } from "@txtdot/sdk";
|
import { Engine } from '@txtdot/sdk';
|
||||||
import questions from "./questions";
|
import questions from './questions';
|
||||||
import users from "./users";
|
import users from './users';
|
||||||
|
|
||||||
const StackOverflow = new Engine(
|
const StackOverflow = new Engine(
|
||||||
"StackOverflow",
|
'StackOverflow',
|
||||||
"Engine for 'StackOverflow' and other 'Stack' sites. Available routes: '/questions/' and '/users/'",
|
"Engine for 'StackOverflow' and other 'Stack' sites. Available routes: '/questions/' and '/users/'",
|
||||||
[
|
[
|
||||||
"stackoverflow.com",
|
'stackoverflow.com',
|
||||||
"*.stackoverflow.com",
|
'*.stackoverflow.com',
|
||||||
"*.stackexchange.com",
|
'*.stackexchange.com',
|
||||||
"askubuntu.com",
|
'askubuntu.com',
|
||||||
"stackapps.com",
|
'stackapps.com',
|
||||||
"mathoverflow.net",
|
'mathoverflow.net',
|
||||||
"superuser.com",
|
'superuser.com',
|
||||||
"serverfault.com",
|
'serverfault.com',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
StackOverflow.route("/questions/:id/*slug", questions);
|
StackOverflow.route('/questions/:id/*slug', questions);
|
||||||
StackOverflow.route("/users/:id/*slug", users);
|
StackOverflow.route('/users/:id/*slug', users);
|
||||||
|
|
||||||
export default StackOverflow;
|
export default StackOverflow;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { HandlerInput, Route } from "@txtdot/sdk/dist/types/handler";
|
import { HandlerInput, Route } from '@txtdot/sdk/dist/types/handler';
|
||||||
|
|
||||||
async function questions(
|
async function questions(
|
||||||
input: HandlerInput,
|
input: HandlerInput,
|
||||||
@ -6,17 +6,17 @@ async function questions(
|
|||||||
) {
|
) {
|
||||||
const document = input.parseDom().window.document;
|
const document = input.parseDom().window.document;
|
||||||
|
|
||||||
const questionEl = document.getElementById("question");
|
const questionEl = document.getElementById('question');
|
||||||
const question = postParser(questionEl);
|
const question = postParser(questionEl);
|
||||||
|
|
||||||
const title = document.querySelector(".question-hyperlink")?.innerHTML || "";
|
const title = document.querySelector('.question-hyperlink')?.innerHTML || '';
|
||||||
|
|
||||||
const allAnswers = [...document.querySelectorAll(".answer")];
|
const allAnswers = [...document.querySelectorAll('.answer')];
|
||||||
const answers = allAnswers.map((a) => postParser(a));
|
const answers = allAnswers.map((a) => postParser(a));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: `${question}<hr>${answers.length} answers <hr>${answers.join(
|
content: `${question}<hr>${answers.length} answers <hr>${answers.join(
|
||||||
"<hr>"
|
'<hr>'
|
||||||
)}`,
|
)}`,
|
||||||
textContent: `${ro.q.id}/${ro.q.slug}\nText output not supported`, // TODO
|
textContent: `${ro.q.id}/${ro.q.slug}\nText output not supported`, // TODO
|
||||||
title,
|
title,
|
||||||
@ -26,23 +26,23 @@ async function questions(
|
|||||||
|
|
||||||
function postParser(el: Element | null): string {
|
function postParser(el: Element | null): string {
|
||||||
if (!el) {
|
if (!el) {
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
const body = el.querySelector(".js-post-body")?.innerHTML || "";
|
const body = el.querySelector('.js-post-body')?.innerHTML || '';
|
||||||
const voteCount = el.querySelector(".js-vote-count")?.textContent || "";
|
const voteCount = el.querySelector('.js-vote-count')?.textContent || '';
|
||||||
|
|
||||||
const footer = [...el.querySelectorAll(".post-signature")].map((el) => {
|
const footer = [...el.querySelectorAll('.post-signature')].map((el) => {
|
||||||
const userName = el.querySelector(".user-details a")?.textContent || "";
|
const userName = el.querySelector('.user-details a')?.textContent || '';
|
||||||
const userUrl =
|
const userUrl =
|
||||||
(el.querySelector(".user-details a") as HTMLAnchorElement)?.href || "";
|
(el.querySelector('.user-details a') as HTMLAnchorElement)?.href || '';
|
||||||
const userTitle = el.querySelector(".user-action-time")?.textContent || "";
|
const userTitle = el.querySelector('.user-action-time')?.textContent || '';
|
||||||
|
|
||||||
return `<h4>${userTitle}${
|
return `<h4>${userTitle}${
|
||||||
userUrl ? ` by <a href="${userUrl}">${userName}</a>` : ""
|
userUrl ? ` by <a href="${userUrl}">${userName}</a>` : ''
|
||||||
}</h4>`;
|
}</h4>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
return `<h3>${voteCount} votes</h3>${body}${footer.join("")}`;
|
return `<h3>${voteCount} votes</h3>${body}${footer.join('')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default questions;
|
export default questions;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as engines from "./engines";
|
import * as engines from './engines';
|
||||||
|
|
||||||
export { engines };
|
export { engines };
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import Route from "route-parser";
|
import Route from 'route-parser';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HandlerInput,
|
HandlerInput,
|
||||||
IHandlerOutput,
|
IHandlerOutput,
|
||||||
EngineFunction,
|
EngineFunction,
|
||||||
RouteValues,
|
RouteValues,
|
||||||
} from "./types/handler";
|
} from './types/handler';
|
||||||
|
|
||||||
import { NoHandlerFoundError } from "./types/errors";
|
import { NoHandlerFoundError } from './types/errors';
|
||||||
|
|
||||||
interface IRoute<TParams extends RouteValues> {
|
interface IRoute<TParams extends RouteValues> {
|
||||||
route: Route;
|
route: Route;
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
import { Engine } from "./engine";
|
import { Engine } from './engine';
|
||||||
|
|
||||||
export { Engine };
|
export { Engine };
|
||||||
|
@ -13,12 +13,12 @@ export abstract class TxtDotError extends Error {
|
|||||||
|
|
||||||
export class NoHandlerFoundError extends TxtDotError {
|
export class NoHandlerFoundError extends TxtDotError {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
super(404, "NoHandlerFoundError", `No handler found for: ${message}`);
|
super(404, 'NoHandlerFoundError', `No handler found for: ${message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EngineParseError extends TxtDotError {
|
export class EngineParseError extends TxtDotError {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
super(422, "EngineParseError", `Parse error: ${message}`);
|
super(422, 'EngineParseError', `Parse error: ${message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { parseHTML } from "linkedom";
|
import { parseHTML } from 'linkedom';
|
||||||
import { Engine } from "../engine";
|
import { Engine } from '../engine';
|
||||||
|
|
||||||
export class HandlerInput {
|
export class HandlerInput {
|
||||||
private data: string;
|
private data: string;
|
||||||
@ -33,19 +33,19 @@ export interface IHandlerOutput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const handlerSchema = {
|
export const handlerSchema = {
|
||||||
type: "object",
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
content: {
|
content: {
|
||||||
type: "string",
|
type: 'string',
|
||||||
},
|
},
|
||||||
textContent: {
|
textContent: {
|
||||||
type: "string",
|
type: 'string',
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
type: "string",
|
type: 'string',
|
||||||
},
|
},
|
||||||
lang: {
|
lang: {
|
||||||
type: "string",
|
type: 'string',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
42
pnpm-lock.yaml
generated
42
pnpm-lock.yaml
generated
@ -8,9 +8,30 @@ importers:
|
|||||||
|
|
||||||
.:
|
.:
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
'@types/node':
|
||||||
|
specifier: ^20.12.7
|
||||||
|
version: 20.12.11
|
||||||
|
'@typescript-eslint/eslint-plugin':
|
||||||
|
specifier: ^7.7.0
|
||||||
|
version: 7.8.0(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.4.5))(eslint@8.57.0)(typescript@5.4.5)
|
||||||
|
'@typescript-eslint/parser':
|
||||||
|
specifier: ^7.7.0
|
||||||
|
version: 7.8.0(eslint@8.57.0)(typescript@5.4.5)
|
||||||
|
eslint:
|
||||||
|
specifier: ^8.56.0
|
||||||
|
version: 8.57.0
|
||||||
lerna:
|
lerna:
|
||||||
specifier: ^8.1.2
|
specifier: ^8.1.2
|
||||||
version: 8.1.2(encoding@0.1.13)
|
version: 8.1.2(encoding@0.1.13)
|
||||||
|
prettier:
|
||||||
|
specifier: ^3.1.1
|
||||||
|
version: 3.2.5
|
||||||
|
tsc-watch:
|
||||||
|
specifier: ^6.2.0
|
||||||
|
version: 6.2.0(typescript@5.4.5)
|
||||||
|
typescript:
|
||||||
|
specifier: ^5.4.5
|
||||||
|
version: 5.4.5
|
||||||
|
|
||||||
packages/plugins:
|
packages/plugins:
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -107,33 +128,12 @@ importers:
|
|||||||
'@types/micromatch':
|
'@types/micromatch':
|
||||||
specifier: ^4.0.7
|
specifier: ^4.0.7
|
||||||
version: 4.0.7
|
version: 4.0.7
|
||||||
'@types/node':
|
|
||||||
specifier: ^20.12.7
|
|
||||||
version: 20.12.11
|
|
||||||
'@typescript-eslint/eslint-plugin':
|
|
||||||
specifier: ^7.7.0
|
|
||||||
version: 7.8.0(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.4.5))(eslint@8.57.0)(typescript@5.4.5)
|
|
||||||
'@typescript-eslint/parser':
|
|
||||||
specifier: ^7.7.0
|
|
||||||
version: 7.8.0(eslint@8.57.0)(typescript@5.4.5)
|
|
||||||
clean-css-cli:
|
clean-css-cli:
|
||||||
specifier: ^5.6.3
|
specifier: ^5.6.3
|
||||||
version: 5.6.3
|
version: 5.6.3
|
||||||
copyfiles:
|
copyfiles:
|
||||||
specifier: ^2.4.1
|
specifier: ^2.4.1
|
||||||
version: 2.4.1
|
version: 2.4.1
|
||||||
eslint:
|
|
||||||
specifier: ^8.56.0
|
|
||||||
version: 8.57.0
|
|
||||||
prettier:
|
|
||||||
specifier: ^3.1.1
|
|
||||||
version: 3.2.5
|
|
||||||
tsc-watch:
|
|
||||||
specifier: ^6.2.0
|
|
||||||
version: 6.2.0(typescript@5.4.5)
|
|
||||||
typescript:
|
|
||||||
specifier: ^5.4.5
|
|
||||||
version: 5.4.5
|
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
packages:
|
packages:
|
||||||
- "packages/*"
|
- 'packages/*'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user