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
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: "20"
|
||||
node-version: '20'
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
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
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: "20"
|
||||
node-version: '20'
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
|
@ -1,5 +1,5 @@
|
||||
import StackOverflow from "./stackoverflow";
|
||||
import Readability from "./readability";
|
||||
import SearX from "./searx";
|
||||
import StackOverflow from './stackoverflow';
|
||||
import Readability from './readability';
|
||||
import SearX from './searx';
|
||||
|
||||
export { StackOverflow, Readability, SearX };
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { Readability as OReadability } from "@mozilla/readability";
|
||||
import { EngineParseError } from "@txtdot/sdk/dist/types/errors";
|
||||
import { Readability as OReadability } from '@mozilla/readability';
|
||||
import { EngineParseError } from '@txtdot/sdk/dist/types/errors';
|
||||
|
||||
import { Engine } from "@txtdot/sdk";
|
||||
import { Engine } from '@txtdot/sdk';
|
||||
|
||||
const Readability = new Engine(
|
||||
"Readability",
|
||||
"Engine for parsing content with Readability",
|
||||
["*"]
|
||||
'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 parsed = reader.parse();
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Engine } from "@txtdot/sdk";
|
||||
import { HandlerInput, Route } from "@txtdot/sdk/dist/types/handler";
|
||||
import { Engine } from '@txtdot/sdk';
|
||||
import { HandlerInput, Route } from '@txtdot/sdk/dist/types/handler';
|
||||
|
||||
const SearX = new Engine("SearX", "Engine for searching with 'SearXNG'", [
|
||||
"searx.*",
|
||||
const SearX = new Engine('SearX', "Engine for searching with 'SearXNG'", [
|
||||
'searx.*',
|
||||
]);
|
||||
|
||||
async function search(
|
||||
@ -11,26 +11,26 @@ async function search(
|
||||
) {
|
||||
const document = input.parseDom().window.document;
|
||||
const search = ro.q.search;
|
||||
const page = parseInt(ro.q.pageno || "1");
|
||||
const page = parseInt(ro.q.pageno || '1');
|
||||
|
||||
const page_footer = `${
|
||||
page !== 1
|
||||
? `<a href="${ro.reverse({ search, pageno: page - 1 })}">Previous </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 parsed = {
|
||||
url:
|
||||
(a.getElementsByClassName("url_wrapper")[0] as HTMLAnchorElement)
|
||||
.href || "",
|
||||
(a.getElementsByClassName('url_wrapper')[0] as HTMLAnchorElement)
|
||||
.href || '',
|
||||
title:
|
||||
(a.getElementsByTagName("h3")[0] as HTMLHeadingElement).textContent ||
|
||||
"",
|
||||
(a.getElementsByTagName('h3')[0] as HTMLHeadingElement).textContent ||
|
||||
'',
|
||||
content:
|
||||
(a.getElementsByClassName("content")[0] as HTMLDivElement)
|
||||
.textContent || "",
|
||||
(a.getElementsByClassName('content')[0] as HTMLDivElement)
|
||||
.textContent || '',
|
||||
};
|
||||
|
||||
return {
|
||||
@ -41,8 +41,8 @@ async function search(
|
||||
|
||||
const content = `${articles_parsed
|
||||
.map((a) => a.html)
|
||||
.join("")}${page_footer}`;
|
||||
const textContent = articles_parsed.map((a) => a.text).join("");
|
||||
.join('')}${page_footer}`;
|
||||
const textContent = articles_parsed.map((a) => a.text).join('');
|
||||
|
||||
return {
|
||||
content,
|
||||
@ -52,7 +52,7 @@ async function search(
|
||||
};
|
||||
}
|
||||
|
||||
SearX.route("/search?q=:search&pageno=:pageno", search);
|
||||
SearX.route("/search?q=:search", search);
|
||||
SearX.route('/search?q=:search&pageno=:pageno', search);
|
||||
SearX.route('/search?q=:search', search);
|
||||
|
||||
export default SearX;
|
||||
|
@ -1,23 +1,23 @@
|
||||
import { Engine } from "@txtdot/sdk";
|
||||
import questions from "./questions";
|
||||
import users from "./users";
|
||||
import { Engine } from '@txtdot/sdk';
|
||||
import questions from './questions';
|
||||
import users from './users';
|
||||
|
||||
const StackOverflow = new Engine(
|
||||
"StackOverflow",
|
||||
'StackOverflow',
|
||||
"Engine for 'StackOverflow' and other 'Stack' sites. Available routes: '/questions/' and '/users/'",
|
||||
[
|
||||
"stackoverflow.com",
|
||||
"*.stackoverflow.com",
|
||||
"*.stackexchange.com",
|
||||
"askubuntu.com",
|
||||
"stackapps.com",
|
||||
"mathoverflow.net",
|
||||
"superuser.com",
|
||||
"serverfault.com",
|
||||
'stackoverflow.com',
|
||||
'*.stackoverflow.com',
|
||||
'*.stackexchange.com',
|
||||
'askubuntu.com',
|
||||
'stackapps.com',
|
||||
'mathoverflow.net',
|
||||
'superuser.com',
|
||||
'serverfault.com',
|
||||
]
|
||||
);
|
||||
|
||||
StackOverflow.route("/questions/:id/*slug", questions);
|
||||
StackOverflow.route("/users/:id/*slug", users);
|
||||
StackOverflow.route('/questions/:id/*slug', questions);
|
||||
StackOverflow.route('/users/:id/*slug', users);
|
||||
|
||||
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(
|
||||
input: HandlerInput,
|
||||
@ -6,17 +6,17 @@ async function questions(
|
||||
) {
|
||||
const document = input.parseDom().window.document;
|
||||
|
||||
const questionEl = document.getElementById("question");
|
||||
const questionEl = document.getElementById('question');
|
||||
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));
|
||||
|
||||
return {
|
||||
content: `${question}<hr>${answers.length} answers <hr>${answers.join(
|
||||
"<hr>"
|
||||
'<hr>'
|
||||
)}`,
|
||||
textContent: `${ro.q.id}/${ro.q.slug}\nText output not supported`, // TODO
|
||||
title,
|
||||
@ -26,23 +26,23 @@ async function questions(
|
||||
|
||||
function postParser(el: Element | null): string {
|
||||
if (!el) {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
const body = el.querySelector(".js-post-body")?.innerHTML || "";
|
||||
const voteCount = el.querySelector(".js-vote-count")?.textContent || "";
|
||||
const body = el.querySelector('.js-post-body')?.innerHTML || '';
|
||||
const voteCount = el.querySelector('.js-vote-count')?.textContent || '';
|
||||
|
||||
const footer = [...el.querySelectorAll(".post-signature")].map((el) => {
|
||||
const userName = el.querySelector(".user-details a")?.textContent || "";
|
||||
const footer = [...el.querySelectorAll('.post-signature')].map((el) => {
|
||||
const userName = el.querySelector('.user-details a')?.textContent || '';
|
||||
const userUrl =
|
||||
(el.querySelector(".user-details a") as HTMLAnchorElement)?.href || "";
|
||||
const userTitle = el.querySelector(".user-action-time")?.textContent || "";
|
||||
(el.querySelector('.user-details a') as HTMLAnchorElement)?.href || '';
|
||||
const userTitle = el.querySelector('.user-action-time')?.textContent || '';
|
||||
|
||||
return `<h4>${userTitle}${
|
||||
userUrl ? ` by <a href="${userUrl}">${userName}</a>` : ""
|
||||
userUrl ? ` by <a href="${userUrl}">${userName}</a>` : ''
|
||||
}</h4>`;
|
||||
});
|
||||
|
||||
return `<h3>${voteCount} votes</h3>${body}${footer.join("")}`;
|
||||
return `<h3>${voteCount} votes</h3>${body}${footer.join('')}`;
|
||||
}
|
||||
|
||||
export default questions;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as engines from "./engines";
|
||||
import * as engines from './engines';
|
||||
|
||||
export { engines };
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
import Route from "route-parser";
|
||||
import Route from 'route-parser';
|
||||
|
||||
import {
|
||||
HandlerInput,
|
||||
IHandlerOutput,
|
||||
EngineFunction,
|
||||
RouteValues,
|
||||
} from "./types/handler";
|
||||
} from './types/handler';
|
||||
|
||||
import { NoHandlerFoundError } from "./types/errors";
|
||||
import { NoHandlerFoundError } from './types/errors';
|
||||
|
||||
interface IRoute<TParams extends RouteValues> {
|
||||
route: Route;
|
||||
|
@ -1,3 +1,3 @@
|
||||
import { Engine } from "./engine";
|
||||
import { Engine } from './engine';
|
||||
|
||||
export { Engine };
|
||||
|
@ -13,12 +13,12 @@ export abstract class TxtDotError extends Error {
|
||||
|
||||
export class NoHandlerFoundError extends TxtDotError {
|
||||
constructor(message: string) {
|
||||
super(404, "NoHandlerFoundError", `No handler found for: ${message}`);
|
||||
super(404, 'NoHandlerFoundError', `No handler found for: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export class EngineParseError extends TxtDotError {
|
||||
constructor(message: string) {
|
||||
super(422, "EngineParseError", `Parse error: ${message}`);
|
||||
super(422, 'EngineParseError', `Parse error: ${message}`);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { parseHTML } from "linkedom";
|
||||
import { Engine } from "../engine";
|
||||
import { parseHTML } from 'linkedom';
|
||||
import { Engine } from '../engine';
|
||||
|
||||
export class HandlerInput {
|
||||
private data: string;
|
||||
@ -33,19 +33,19 @@ export interface IHandlerOutput {
|
||||
}
|
||||
|
||||
export const handlerSchema = {
|
||||
type: "object",
|
||||
type: 'object',
|
||||
properties: {
|
||||
content: {
|
||||
type: "string",
|
||||
type: 'string',
|
||||
},
|
||||
textContent: {
|
||||
type: "string",
|
||||
type: 'string',
|
||||
},
|
||||
title: {
|
||||
type: "string",
|
||||
type: 'string',
|
||||
},
|
||||
lang: {
|
||||
type: "string",
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
42
pnpm-lock.yaml
generated
42
pnpm-lock.yaml
generated
@ -8,9 +8,30 @@ importers:
|
||||
|
||||
.:
|
||||
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:
|
||||
specifier: ^8.1.2
|
||||
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:
|
||||
dependencies:
|
||||
@ -107,33 +128,12 @@ importers:
|
||||
'@types/micromatch':
|
||||
specifier: ^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:
|
||||
specifier: ^5.6.3
|
||||
version: 5.6.3
|
||||
copyfiles:
|
||||
specifier: ^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:
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
packages:
|
||||
- "packages/*"
|
||||
- 'packages/*'
|
||||
|
Loading…
x
Reference in New Issue
Block a user