diff options
Diffstat (limited to 'rust')
-rw-r--r-- | rust/wolfree_libredirect_patch/Cargo.toml | 21 | ||||
-rw-r--r-- | rust/wolfree_libredirect_patch/src/body.md | 68 | ||||
-rw-r--r-- | rust/wolfree_libredirect_patch/src/head.html | 43 | ||||
-rw-r--r-- | rust/wolfree_libredirect_patch/src/instances.json | 14 | ||||
-rw-r--r-- | rust/wolfree_libredirect_patch/src/main.rs | 95 | ||||
-rw-r--r-- | rust/wolfree_sed_in_place/Cargo.toml | 22 | ||||
-rw-r--r-- | rust/wolfree_sed_in_place/src/include_str.html | 76 | ||||
-rw-r--r-- | rust/wolfree_sed_in_place/src/include_str.tsx | 71 | ||||
-rw-r--r-- | rust/wolfree_sed_in_place/src/main.rs | 115 |
9 files changed, 525 insertions, 0 deletions
diff --git a/rust/wolfree_libredirect_patch/Cargo.toml b/rust/wolfree_libredirect_patch/Cargo.toml new file mode 100644 index 0000000..5b587d5 --- /dev/null +++ b/rust/wolfree_libredirect_patch/Cargo.toml @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# This file is part of Wolfree. +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +[package] +name = "wolfree_libredirect_patch" +version = "23.7.31" +edition = "2021" + +authors = ["See the commit history of the Git repositories: <https://try.gitea.io/wolfree>"] +description = "The Rust crate provides lightweight wrappers around the `fs::write` and `fs::remove_dir_all` functions from the standard library's `fs` module." +license = "AGPL-3.0-or-later" +repository = "https://try.gitea.io/wolfree" +readme = "README.md" +keywords = ["rust", "wrapper", "write", "remove", "file"] +categories = ["command-line-utilities", "development-tools::build-utils", "web-programming"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +markdown = "1.0.0-alpha" diff --git a/rust/wolfree_libredirect_patch/src/body.md b/rust/wolfree_libredirect_patch/src/body.md new file mode 100644 index 0000000..69ccfc1 --- /dev/null +++ b/rust/wolfree_libredirect_patch/src/body.md @@ -0,0 +1,68 @@ +# Paywall-Respecting Instances: Wolfree instances that do not bypass any paywall + +Welcome to Paywall-Respecting Instances, where we provide Wolfree instances that **do not bypass any paywall**. + +## The Problem with Other Wolfree Instances + +Most other Wolfree instances can bypass paywalls, which raises concerns about Microsoft GitHub's [DMCA Takedown Policy](https://docs.github.com/en/site-policy/content-removal-policies/dmca-takedown-policy). + +Unfortunately, this means that developers of [LibRedirect](https://libredirect.github.io/) cannot redirect users to such instances. + +To learn more about this issue, please refer to [issue #425](https://github.com/libredirect/browser_extension/issues/425) on Microsoft GitHub. + +## The Solution: Paywall-Respecting Instances + +Unlike other Wolfree instances, Paywall-Respecting Instances prioritize ethical practices and **do not bypass any paywall**. So developers of LibRedirect can confidently redirect their users to Paywall-Respecting Instances. + +## Instance List + +Here are some Paywall-Respecting Instances you can access: + +1. https://gqq.gitlab.io/ +2. https://jqq.gitlab.io/ +3. https://rqq.gitlab.io/ +4. https://sqq.gitlab.io/ +5. https://uqq.gitlab.io/ + +JSON: [instances.json](/instances.json) + +## Source Code + +Paywall-Respecting Instances is free and open-source software. You can access and download its source code from the following websites: + +1. https://try.gitea.io/wolfree +2. https://codeberg.org/wolfree +3. https://git.disroot.org/wolfree +4. https://next.forgejo.org/wolfree +5. https://git.kiwifarms.net/wolfree +6. http://it7otdanqu7ktntxzm427cba6i53w6wlanlh23v5i3siqmos47pzhvyd.onion/wolfree + +SPDX-License-Identifier: AGPL-3.0-or-later + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +## How it Works + +1. Install [LibRedirect](https://libredirect.github.io/) on your web browser. +2. LibRedirect automatically redirects you from Wolfram to our instances, safeguarding your privacy. +3. Enjoy accessing Wolfree instances that uphold ethical practices and **do not bypass any paywall**. + +## Key Features + +### Compliance with Microsoft GitHub + +Paywall-Respecting Instances **do not bypass any paywall**, empowering LibRedirect developers with the confidence to redirect users to our instances. + +### Protect Your Privacy + +Once you install LibRedirect on your web browser, LibRedirect automatically redirects you from Wolfram to our instances, securing your digital privacy. + +### Ethical Practices + +By accessing our instances, you actively promote ethical practices and support the work of content creators. + +## Get Started Now! + +Install LibRedirect to access Paywall-Respecting Instances. Enjoy Wolfree instances that **do not bypass any paywall**. + +- [Install LibRedirect](https://libredirect.github.io/) diff --git a/rust/wolfree_libredirect_patch/src/head.html b/rust/wolfree_libredirect_patch/src/head.html new file mode 100644 index 0000000..d67963c --- /dev/null +++ b/rust/wolfree_libredirect_patch/src/head.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="description" + content="With our seamless integration with LibRedirect, a web browser extension that protects your digital privacy, you can ensure that your access to Wolfree instances preserves your privacy and complies with Microsoft GitHub's DMCA Takedown Policy." /> + <title> + Wolfree instances that do not bypass any paywall | Paywall-Respecting Instances + </title> + <style> + html { + margin: 1rem; + font-family: sans-serif; + } + + body { + max-width: 30rem; + margin: 5rem auto; + } + + h1, + h2 { + margin-top: 5rem; + line-height: 1.5; + } + + p, + li { + line-height: 2; + } + + a { + text-decoration: none; + word-wrap: break-word; + } + </style> + <link rel="icon" href="data:," /> +</head> + +</html> +<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
\ No newline at end of file diff --git a/rust/wolfree_libredirect_patch/src/instances.json b/rust/wolfree_libredirect_patch/src/instances.json new file mode 100644 index 0000000..8cdd008 --- /dev/null +++ b/rust/wolfree_libredirect_patch/src/instances.json @@ -0,0 +1,14 @@ +{ + "wolfree": { + "clearnet": [ + "https://gqq.gitlab.io/", + "https://jqq.gitlab.io/", + "https://rqq.gitlab.io/", + "https://sqq.gitlab.io/", + "https://uqq.gitlab.io/" + ], + "tor": [], + "i2p": [], + "loki": [] + } +} diff --git a/rust/wolfree_libredirect_patch/src/main.rs b/rust/wolfree_libredirect_patch/src/main.rs new file mode 100644 index 0000000..65f1b93 --- /dev/null +++ b/rust/wolfree_libredirect_patch/src/main.rs @@ -0,0 +1,95 @@ +//! The Rust crate provides lightweight wrappers around the `fs::write` and `fs::remove_dir_all` functions from the standard library's `fs` module. +//! The crate is designed to simplify file writing and directory removal operations by encapsulating the error handling logic and providing a more convenient interface. +//! It is particularly useful for tasks that involve writing multiple files or removing directories with their contents. + +#![allow(clippy::blanket_clippy_restriction_lints)] +#![allow(clippy::exit)] +#![allow(clippy::print_stderr)] +#![allow(clippy::implicit_return)] + +/* SPDX-License-Identifier: AGPL-3.0-or-later + * This file is part of Wolfree. + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + */ + +use markdown::to_html_with_options; +use markdown::Options; +use std::fs; + +/// A lightweight wrapper around `fs::write`. +fn wolfree_write(file_path: &str, contents: &str) { + match fs::write(file_path, contents) { + Ok(_) => (), + Err(err) => { + eprintln!("Error: {err}",); + std::process::exit(1); + } + }; +} + +/// A lightweight wrapper around `fs::remove_dir_all`. +fn wolfree_remove_dir_all(dir_path: &str) { + match fs::remove_dir_all(dir_path) { + Ok(_) => (), + Err(err) => { + eprintln!("Error: {err}",); + std::process::exit(1); + } + }; +} + +/// A lightweight wrapper around `markdown::to_html_with_options`. +fn wolfree_to_html_with_options(value: &str) -> String { + match to_html_with_options(value, &Options::gfm()) { + Ok(result) => result, + Err(err) => { + eprintln!("Error: {err}",); + std::process::exit(1); + } + } +} + +/// Entry point of the program. +fn main() { + wolfree_write( + "./docusaurus/build/ajax/libs/wolfree/23.7.8/js/Entrypoint.js", + "export default () => {}", + ); + wolfree_write( + "./docusaurus/build/index.html", + &format!( + "{}{}", + include_str!("head.html"), + wolfree_to_html_with_options(include_str!("body.md")), + ), + ); + wolfree_write( + "./docusaurus/build/instances.json", + include_str!("instances.json"), + ); + wolfree_write( + "./docusaurus/build/404.html", + "<script>location='/'</script>", + ); + wolfree_write( + "./docusaurus/build/acknowledgment/index.html", + "<script>location='/'</script>", + ); + wolfree_write( + "./docusaurus/build/community/index.html", + "<script>location='/'</script>", + ); + wolfree_write( + "./docusaurus/build/dmca/index.html", + "<script>location='/'</script>", + ); + wolfree_write( + "./docusaurus/build/mirror/index.html", + "<script>location='/'</script>", + ); + wolfree_write( + "./docusaurus/build/source/index.html", + "<script>location='/'</script>", + ); + wolfree_remove_dir_all("./docusaurus/build/assets/"); +} diff --git a/rust/wolfree_sed_in_place/Cargo.toml b/rust/wolfree_sed_in_place/Cargo.toml new file mode 100644 index 0000000..ab2b32f --- /dev/null +++ b/rust/wolfree_sed_in_place/Cargo.toml @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# This file is part of Wolfree. +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +[package] +name = "wolfree_sed_in_place" +version = "23.7.31" +edition = "2021" + +authors = ["See the commit history of the Git repositories: <https://try.gitea.io/wolfree>"] +description = "This Rust program performs in-place search and replaces operations on all files within specified directories. It uses regular expressions to find occurrences of a given pattern in each file's contents and replaces them with the replacement text." +license = "AGPL-3.0-or-later" +repository = "https://try.gitea.io/wolfree" +readme = "README.md" +keywords = ["rust", "search", "replace", "regular expressions", "regex", "file", "in-place"] +categories = ["command-line-utilities", "development-tools::build-utils", "web-programming", "template-engine"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +regex = "1" +walkdir = "2" diff --git a/rust/wolfree_sed_in_place/src/include_str.html b/rust/wolfree_sed_in_place/src/include_str.html new file mode 100644 index 0000000..2fbe0f4 --- /dev/null +++ b/rust/wolfree_sed_in_place/src/include_str.html @@ -0,0 +1,76 @@ +<meta name="referrer" content="no-referrer" /> + +<script type="module" src="/ajax/libs/jquery/3.7.0/jquery.min.js"></script> +<script type="module" src="/ajax/libs/dompurify/3.0.5/purify.min.js"></script> +<script type="module" src="/ajax/libs/wolfree/23.7.8/js/onload.js"></script> + +<link rel="preload" as="style" onload="this.onload = null; this.rel = 'stylesheet';" + href="/ajax/libs/wolfree/23.7.8/css/Placeholder.css" /> +<link rel="preload" as="style" onload="this.onload = null; this.rel = 'stylesheet';" + href="/ajax/libs/wolfree/23.7.8/css/PodsParser.css" /> + +<style> + html>body>#__next>div>header { + visibility: hidden; + height: 5rem; + } + + html>body>#__next>div>footer { + visibility: hidden; + } + + html>body>#__next>div>main>main>span, + html>body>#__next>div>main>main a[href*="/pro/pricing/students/"], + html>body>#__next>div>main>main a[href*="/pro/pricing/students/"]~*, + html>body>#__next>div>main>main>div>a, + html>body>#__next>div>main>main>div>a>img[src*="../_next/static/images/Logo_"][alt*="WolframAlpha computational knowledge AI"], + html>body>#__next>div>main>main>div>div>nav>a~button, + html>body>#__next>div>main>main>div>div>nav>div>div>ul>li~li~li, + /* Derivative[9][y][x] == y[x] */ + html>body>#__next>div>main>main>div>div>div[class=""], + html>body>#__next>div>main>main>div>div>div>section>section> :not(div, ul, header, button), + /* Wolfram|Alpha Copyable Plain Text */ + html>body>#__next>div>main>main>div>div>div>section>section>header>h2> :not(span), + html>body>#__next>div>main>main>div>div>div>section>section>div> :not(h2, select, span, div), + html>body>#__next>div>main>main>div>div>div>section>section>div>div> :not(img, button, div, a), + html>body>#__next>div>main>main a[href*="/pro/pricing/"], + html>body>#__next>div>main>main a[href*="/pro/pricing/"]~*, + html>body>#__next>div>main>main a[href*="/pro-premium-expert-support"], + html>body>#__next>div>main>main a[href*="/pro-premium-expert-support"]~*, + /* "isGDPR": true */ + html>body>#__next>div>section { + display: none; + } + + html>body>header { + position: absolute; + width: 100%; + z-index: 1; + } + + html>body>header>nav { + text-align: center; + display: flex; + max-width: 780px; + margin: auto; + } + + html>body>header>nav>a { + font-family: sans-serif; + text-decoration: none; + flex: auto; + margin: 1rem 0; + padding: 1rem 0; + } +</style> + +$0 + +<header> + <nav> + <a href="../">Wolfree</a> + <a href="../mirror">Mirror</a> + <a href="../source">Source</a> + </nav> +</header> +<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
\ No newline at end of file diff --git a/rust/wolfree_sed_in_place/src/include_str.tsx b/rust/wolfree_sed_in_place/src/include_str.tsx new file mode 100644 index 0000000..3c8ff4e --- /dev/null +++ b/rust/wolfree_sed_in_place/src/include_str.tsx @@ -0,0 +1,71 @@ +/** + * @license + * SPDX-License-Identifier: AGPL-3.0-or-later + * This file is part of Wolfree. + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + */ + +// @ts-check + +const wolfreeLexicalScopeName = (() => { + const possibleLetters = Array(); + + for (let i = 32; i < 127; i++) { + possibleLetters.push(String.fromCharCode(i)); + } + + const possibleNames = possibleLetters.flatMap((x) => + possibleLetters.map((y) => x + y) + ); + + const isValid = (name = String()) => { + try { + return ( + typeof eval(name).value === "string" && + typeof eval(name).i2d === "boolean" + ); + } catch (error) { + return false; + } + }; + + const wolfreeLexicalScopeName = possibleNames.find(isValid); + + if (typeof wolfreeLexicalScopeName !== "string") { + console.error({ wolfreeLexicalScopeName }); + return ""; + } + + return wolfreeLexicalScopeName; +})(); + +(() => { + const get = (params = String()) => { + return new URLSearchParams(location.search).get(params); + }; + + eval(wolfreeLexicalScopeName).value = get("i") || "topic mathematics"; + eval(wolfreeLexicalScopeName).i2d = get("i2d") === "true"; +})(); + +/** + * Regex in regex - Rust + * https://docs.rs/regex/latest/regex/struct.Regex.html#replacement-string-syntax + * All instances of $ref in the replacement string are replaced with the substring corresponding to the capture group identified by ref. + * ref may be an integer corresponding to the index of the capture group (counted by order of opening parenthesis where 0 is the entire match) or it can be a name (consisting of letters, digits or underscores) corresponding to a named capture group. + */ +// @ts-ignore +$0; + +(async () => { + ( + await import( + // @ts-ignore + "../../../ajax/libs/wolfree/23.7.8/js/Entrypoint.js" + ) + ).default({ + input: eval(wolfreeLexicalScopeName).value, + i2d: eval(wolfreeLexicalScopeName).i2d, + extraPodstates: [], + }); +})(); diff --git a/rust/wolfree_sed_in_place/src/main.rs b/rust/wolfree_sed_in_place/src/main.rs new file mode 100644 index 0000000..7d56889 --- /dev/null +++ b/rust/wolfree_sed_in_place/src/main.rs @@ -0,0 +1,115 @@ +//! The `wolfree_sed_in_place` crate provides a function for performing in-place replacements of patterns in multiple files using regular expressions. +//! It allows you to recursively process all files within a specified directory and replace occurrences of a given pattern with a specified replacement string. + +#![allow(clippy::blanket_clippy_restriction_lints)] +#![allow(clippy::exit)] +#![allow(clippy::print_stderr)] +#![allow(clippy::implicit_return)] + +/* SPDX-License-Identifier: AGPL-3.0-or-later + * This file is part of Wolfree. + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + */ + +use regex::Regex; +use std::fs; +use walkdir::WalkDir; + +/// Perform in-place replacements on files in a given directory, using regular expressions. +/// +/// This function walks through all the files in the specified `directory_path`, +/// filters out directories, and applies a regular expression-based replacement +/// on the contents of each file. +/// +/// # Arguments +/// +/// * `directory_path`: A string slice representing the path of the directory to traverse. +/// * `pattern`: A string slice containing the regular expression pattern to search for. +/// * `replacement`: A string slice representing the replacement for each matched pattern. +/// +/// # Examples +/// +/// ```rust +/// // Replace a specific pattern in the file contents in the "./data/" directory. +/// wolfree_sed_in_place("./data/", r"\bFoo\b", "Bar"); +/// ``` +/// +/// This example replaces all occurrences of the word "Foo" with "Bar" in the files inside the "data" directory. +fn wolfree_sed_in_place(directory_path: &str, pattern: &str, replacement: &str) { + // Compile the regular expression pattern + let regex = match Regex::new(pattern) { + Ok(re) => re, + Err(err) => { + eprintln!("Error: {err}",); + std::process::exit(1); + } + }; + + // Create a directory walker and filter out non-file entries + let walker = WalkDir::new(directory_path) + .into_iter() + .filter_map(Result::ok) + .filter(|entry| !entry.file_type().is_dir()); + + // Process each file in the directory + for entry in walker { + let file_path = entry.path(); + + // Read the file's contents into a string + let file_contents = match fs::read_to_string(file_path) { + Ok(contents) => contents, + Err(err) => { + eprintln!("Error: {err}",); + std::process::exit(1); + } + }; + + // Perform the regex replacement on the file's contents + let modified_contents = regex.replace(&file_contents, replacement); + let modified_contents_as_ref = modified_contents.as_ref(); + + // Write the modified contents back to the file, overwriting its previous contents + match fs::write(file_path, modified_contents_as_ref) { + Ok(_) => (), + Err(err) => { + eprintln!("Error: {err}",); + std::process::exit(1); + } + }; + } +} + +/// Entry point of the program. +/// Demonstrates using `wolfree_sed_in_place` function to perform in-place replacements on files in specific directories. +fn main() { + wolfree_sed_in_place( + "./docusaurus/build/input/", + "</head><body>", + include_str!("include_str.html"), + ); + + wolfree_sed_in_place( + "./docusaurus/build/_next/static/chunks/", + r"try(.{0,100}?)generateEncodedJSONFromValue(.*?)unescapeForUrl(.*?)catch(.*?)\{}", + include_str!("include_str.tsx"), + ); + + // console error: + // _app-daabd76ef4fe402d.js:5 + // WebSocket connection to 'wss://localhost/n/v1/api/fetcher/results' failed: + // startWebsocket @ _app-daabd76ef4fe402d.js:5 + // send @ _app-daabd76ef4fe402d.js:5 + // sendMessage @ 1695-ae743311a23f8eb5.js:1 + // newQuery @ 1695-ae743311a23f8eb5.js:78 + // newQuery @ 1695-ae743311a23f8eb5.js:78 + // fix: + // Override the hostname in the minified JavaScript source code. + wolfree_sed_in_place( + "./docusaurus/build/_next/static/chunks/pages/", + "window.location.hostname", + "'www.wolframalpha.com'", + ); +} + +// regex101: build, test, and debug regex +// https://regex101.com/ |