Skip to content

Commit

Permalink
Dev (#207)
Browse files Browse the repository at this point in the history
* feat: big badge configuration

* fix: remove google fonts

* fix(plugins, server): remove cdn

* ci: fix format ignore

* feat(server): json configuration

* feat: add search route for adding in browser

* fix: add arm arch

* fix: docker action

* fix: engines fallback

* doc: change logo

* doc: fix logo margin

* doc: update version

* doc: change layout

* dev: add dependabot groups

* dev: fix dependabot and format
  • Loading branch information
artegoser authored Jul 24, 2024
1 parent d0bc4ff commit 572531a
Show file tree
Hide file tree
Showing 23 changed files with 2,199 additions and 1,024 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
packages/**/dist/**/*
packages/**/node_modules/**/*
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ updates:
target-branch: 'dev'
schedule:
interval: 'weekly'
groups:
deps:
patterns:
- '*'
File renamed without changes.
53 changes: 0 additions & 53 deletions .github/workflows/deploy.yml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create and publish a Docker image

on:
push:
branches:
- main
- dev
release:
types:
- published

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pnpm-lock.yaml
packages/**/dist/**/*
packages/**/dist/**/*
packages/**/node_modules/**/*
packages/server/static/third-party/**/*
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<h1 align="center">
<a href="https://github.com/TxtDot/txtdot"><img src="https://github.com/TxtDot/.github/blob/main/imgs/TXTDot%20gh.png?raw=true" alt="txt." width="200"></a>
<br>
<a href="https://txtdot.github.io/documentation"><img alt="Documentation" src="https://img.shields.io/badge/Documentation-green"></a>
<a href="https://github.com/TxtDot/instances"><img alt="Instances" src="https://img.shields.io/badge/Instances-green"></a>
<br>
<a href="https://github.com/TxtDot/txtdot/blob/main/LICENSE"><img alt="MIT license" src="https://img.shields.io/github/license/txtdot/txtdot?color=blue"></a>
<a href="https://github.com/TxtDot/txtdot/releases/latest"><img alt="Latest release" src="https://img.shields.io/github/v/release/TxtDot/txtdot?display_name=release"></a>
<a href="https://matrix.to/#/#txtdot:matrix.org"><img alt="Matrix chat" src="https://img.shields.io/badge/chat-matrix-blue"></a>
</h1>
<div align="center">

![txtdot logo](https://github.com/TxtDot/.github/raw/main/imgs/txtdot.png)

<a href="https://txtdot.github.io/documentation"><img alt="Documentation" src="https://img.shields.io/badge/Documentation-blue"></a>
<a href="https://github.com/TxtDot/instances"><img alt="Instances" src="https://img.shields.io/badge/Instances-blue"></a>
<br>
<a href="https://github.com/TxtDot/txtdot/blob/main/LICENSE"><img alt="MIT license" src="https://img.shields.io/github/license/txtdot/txtdot?color=blue"></a>
<a href="https://github.com/TxtDot/txtdot/releases/latest"><img alt="Latest release" src="https://img.shields.io/github/v/release/TxtDot/txtdot?display_name=release"></a>

# txtdot

</div>

HTTP proxy that parses only text, links and pictures from pages
reducing internet traffic, removing ads and heavy scripts.
Expand Down
10 changes: 4 additions & 6 deletions packages/plugins/src/middlewares/highlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ function Highlighter({ content }: { content: string }) {
return (
<>
<style>
@import
"https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/atom-one-light.min.css";
@import
"https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/atom-one-dark.min.css"
screen and (prefers-color-scheme: dark);
@import "/static/third-party/styles/atom-one-light.min.css"; @import
"/static/third-party/styles/atom-one-dark.min.css" screen and
(prefers-color-scheme: dark);
</style>
<script
src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"
src="/static/third-party/scripts/highlight.min.js"
type="text/javascript"
/>
<script>hljs.highlightAll();</script>
Expand Down
8 changes: 4 additions & 4 deletions packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@txtdot/server",
"version": "1.8.0",
"version": "1.9.0",
"private": true,
"description": "txtdot is an HTTP proxy that parses only text, links and pictures from pages reducing internet bandwidth usage, removing ads and heavy scripts",
"main": "dist/app.js",
Expand All @@ -12,7 +12,7 @@
"license": "MIT",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npm run clean-css && copyfiles ./templates/*.ejs ./templates/**/*.ejs .env ./dist/ && tsc",
"build": "npm run clean-css && copyfiles ./templates/*.ejs ./templates/**/*.ejs ./static/third-party/* ./static/third-party/**/* .env ./dist/ && tsc",
"start": "cd ./dist && node ./src/app.js",
"clean-css": "cleancss --batch static/*.css -o dist/static --batch-suffix \"\"",
"dev": "tsc-watch --onSuccess \"node ./dist/src/app.js\""
Expand All @@ -21,7 +21,7 @@
"@fastify/one-line-logger": "^1.3.0",
"@fastify/static": "^7.0.3",
"@fastify/swagger": "^8.14.0",
"@fastify/swagger-ui": "^3.0.0",
"@fastify/swagger-ui": "^4.0.0",
"@fastify/view": "^9.0.0",
"@txtdot/plugins": "workspace:*",
"@txtdot/sdk": "workspace:*",
Expand All @@ -32,7 +32,7 @@
"iconv-lite": "^0.6.3",
"ip-range-check": "^0.2.0",
"isomorphic-dompurify": "^2.10.0",
"json-schema-to-ts": "^3.0.1",
"json-schema-to-ts": "^3.1.0",
"linkedom": "^0.18.0",
"micromatch": "^4.0.5",
"sharp": "^0.33.3"
Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/distributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ export class Distributor {
}
}

return await this.engines_fallback[0].handle(input);
return await this.engines_fallback[this.engines_fallback.length - 1].handle(
input
);
}

async processMiddlewares(
Expand Down
68 changes: 61 additions & 7 deletions packages/server/src/routes/browser/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,65 @@ import { indexSchema } from '../../types/requests/browser';
import config from '../../config';

export default async function configurationRoute(fastify: FastifyInstance) {
fastify.get('/configuration', { schema: indexSchema }, async (_, reply) => {
return reply.view('/templates/configuration.ejs', {
engines: distributor.engines_fallback,
middlewares: distributor.middles_fallback,
config,
});
});
fastify.get(
'/configuration',
{ schema: indexSchema },
async (request, reply) => {
return reply.view('/templates/configuration.ejs', {
engines: distributor.engines_fallback,
middlewares: distributor.middles_fallback,
config,
base_url: `(${request.protocol}) - ${request.hostname}`,
});
}
);

fastify.get(
'/configuration/json',
{ schema: indexSchema },
async (request, reply) => {
reply.header('content-type', 'application/json');

return {
protocol: request.protocol,
hostname: request.hostname,
version: config.package.version,
...{ ...config.env, host: undefined, port: undefined },
engines: distributor.engines_fallback.map((engine) => {
return {
...engine,
routes: engine.routes.map((route) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (route.route as any).spec;
}),
};
}),
middlewares: distributor.middles_fallback.map((middleware) => {
return {
...middleware,
routes: middleware.middles.map((middle) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (middle.route as any).spec;
}),
middles: undefined,
};
}),
routes: [...config.dyn.routes].map((route) => {
return route;
}),
};
}
);

fastify.get(
'/configuration/badges/big',
{ schema: indexSchema },
async (request, reply) => {
reply.header('content-type', 'image/svg+xml');
return reply.view('/templates/big_badge.ejs', {
config,
base_url: `(${request.protocol}) - ${request.hostname}`,
});
}
);
}
25 changes: 24 additions & 1 deletion packages/server/src/routes/browser/redirect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { FastifyInstance } from 'fastify';

import { redirectSchema, IRedirectSchema } from '../../types/requests/browser';
import {
redirectSchema,
IRedirectSchema,
ISearchSchema,
searchSchema,
} from '../../types/requests/browser';

import config from '../../config';

export default async function redirectRoute(fastify: FastifyInstance) {
fastify.get<IRedirectSchema>(
Expand All @@ -17,4 +24,20 @@ export default async function redirectRoute(fastify: FastifyInstance) {
);
}
);

if (config.env.third_party.searx_url) {
fastify.get<ISearchSchema>(
'/search',
{ schema: searchSchema },
async (request, reply) => {
reply.redirect(
`/get?url=${encodeURIComponent(
config.env.third_party.searx_url +
'/search?q=' +
encodeURIComponent(request.query.q)
)}`
);
}
);
}
}
Loading

0 comments on commit 572531a

Please sign in to comment.