From 72d8b4e6bee0ffac79e96dd649a9da2adb86b507 Mon Sep 17 00:00:00 2001 From: name Date: Wed, 27 Sep 2023 11:34:23 +0000 Subject: 2023-09-26 --- rust/wolfree_download_dependencies/Cargo.toml | 20 ++++ rust/wolfree_download_dependencies/src/main.rs | 22 ++++ rust/wolfree_libredirect_patch/Cargo.toml | 21 ---- rust/wolfree_libredirect_patch/src/body.md | 68 ------------- rust/wolfree_libredirect_patch/src/head.html | 43 -------- rust/wolfree_libredirect_patch/src/instances.json | 14 --- rust/wolfree_libredirect_patch/src/main.rs | 95 ----------------- rust/wolfree_patch_libredirect/Cargo.toml | 28 +++++ .../src/docusaurus/docs/index.mdx | 81 +++++++++++++++ .../src/docusaurus/docs/mirror.mdx | 24 +++++ .../src/docusaurus/docs/source.mdx | 22 ++++ .../src/docusaurus/static/instances.json | 14 +++ rust/wolfree_patch_libredirect/src/main.rs | 40 ++++++++ rust/wolfree_sed_in_place/Cargo.toml | 25 +++-- rust/wolfree_sed_in_place/src/include_str.html | 17 ++-- rust/wolfree_sed_in_place/src/include_str.js | 65 ++++++++++++ rust/wolfree_sed_in_place/src/include_str.tsx | 71 ------------- rust/wolfree_sed_in_place/src/main.rs | 113 +++++++-------------- 18 files changed, 375 insertions(+), 408 deletions(-) create mode 100644 rust/wolfree_download_dependencies/Cargo.toml create mode 100644 rust/wolfree_download_dependencies/src/main.rs delete mode 100644 rust/wolfree_libredirect_patch/Cargo.toml delete mode 100644 rust/wolfree_libredirect_patch/src/body.md delete mode 100644 rust/wolfree_libredirect_patch/src/head.html delete mode 100644 rust/wolfree_libredirect_patch/src/instances.json delete mode 100644 rust/wolfree_libredirect_patch/src/main.rs create mode 100644 rust/wolfree_patch_libredirect/Cargo.toml create mode 100644 rust/wolfree_patch_libredirect/src/docusaurus/docs/index.mdx create mode 100644 rust/wolfree_patch_libredirect/src/docusaurus/docs/mirror.mdx create mode 100644 rust/wolfree_patch_libredirect/src/docusaurus/docs/source.mdx create mode 100644 rust/wolfree_patch_libredirect/src/docusaurus/static/instances.json create mode 100644 rust/wolfree_patch_libredirect/src/main.rs create mode 100644 rust/wolfree_sed_in_place/src/include_str.js delete mode 100644 rust/wolfree_sed_in_place/src/include_str.tsx (limited to 'rust') diff --git a/rust/wolfree_download_dependencies/Cargo.toml b/rust/wolfree_download_dependencies/Cargo.toml new file mode 100644 index 0000000..a76607d --- /dev/null +++ b/rust/wolfree_download_dependencies/Cargo.toml @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later + +[package] +name = "wolfree_download_dependencies" +version = "2023.8.31" +authors = [ + "See the commit history of the Git repositories.", + "https://git.kiwifarms.net/wolfree", +] +categories = ["development-tools::build-utils"] +edition = "2021" +keywords = ["Wolfree", "Docker", "download", "compile", "dependency"] +license = "AGPL-3.0-or-later" +readme = "README.md" +repository = "https://git.kiwifarms.net/wolfree" +description = "Download and compile dependencies." + +[dependencies] +regex = "1" +walkdir = "2" diff --git a/rust/wolfree_download_dependencies/src/main.rs b/rust/wolfree_download_dependencies/src/main.rs new file mode 100644 index 0000000..9fdc1ab --- /dev/null +++ b/rust/wolfree_download_dependencies/src/main.rs @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ + +//! rust - Can Cargo download and build dependencies without also building the application? - Stack Overflow +//! +//! +//! cargo build --dependencies-only · Issue #2644 · rust-lang/cargo · GitHub +//! + +#![allow(clippy::blanket_clippy_restriction_lints)] +#![allow(clippy::implicit_return)] +#![allow(clippy::question_mark_used)] + +use regex::Regex; +use std::error; +use walkdir::WalkDir; + +/// Entry point of the program. +fn main() -> Result<(), Box> { + let _: Regex = Regex::new("")?; + let _: WalkDir = WalkDir::new(""); + Ok(()) +} diff --git a/rust/wolfree_libredirect_patch/Cargo.toml b/rust/wolfree_libredirect_patch/Cargo.toml deleted file mode 100644 index 5b587d5..0000000 --- a/rust/wolfree_libredirect_patch/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -# 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: "] -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 deleted file mode 100644 index 69ccfc1..0000000 --- a/rust/wolfree_libredirect_patch/src/body.md +++ /dev/null @@ -1,68 +0,0 @@ -# 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 deleted file mode 100644 index d67963c..0000000 --- a/rust/wolfree_libredirect_patch/src/head.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - Wolfree instances that do not bypass any paywall | Paywall-Respecting Instances - - - - - - - \ No newline at end of file diff --git a/rust/wolfree_libredirect_patch/src/instances.json b/rust/wolfree_libredirect_patch/src/instances.json deleted file mode 100644 index 8cdd008..0000000 --- a/rust/wolfree_libredirect_patch/src/instances.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "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 deleted file mode 100644 index 65f1b93..0000000 --- a/rust/wolfree_libredirect_patch/src/main.rs +++ /dev/null @@ -1,95 +0,0 @@ -//! 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", - "", - ); - wolfree_write( - "./docusaurus/build/acknowledgment/index.html", - "", - ); - wolfree_write( - "./docusaurus/build/community/index.html", - "", - ); - wolfree_write( - "./docusaurus/build/dmca/index.html", - "", - ); - wolfree_write( - "./docusaurus/build/mirror/index.html", - "", - ); - wolfree_write( - "./docusaurus/build/source/index.html", - "", - ); - wolfree_remove_dir_all("./docusaurus/build/assets/"); -} diff --git a/rust/wolfree_patch_libredirect/Cargo.toml b/rust/wolfree_patch_libredirect/Cargo.toml new file mode 100644 index 0000000..cf55e4d --- /dev/null +++ b/rust/wolfree_patch_libredirect/Cargo.toml @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later + +[package] +name = "wolfree_patch_libredirect" +version = "2023.8.31" +authors = [ + "See the commit history of the Git repositories.", + "https://git.kiwifarms.net/wolfree", +] +categories = [ + "command-line-utilities", + "development-tools::build-utils", + "web-programming", +] +edition = "2021" +keywords = [ + "rust", + "customize", + "Wolfree", + "LibRedirect", + "write", + "remove", + "file", +] +license = "AGPL-3.0-or-later" +readme = "README.md" +repository = "https://git.kiwifarms.net/wolfree" +description = "Customize Wolfree instances to suit Libredirect." diff --git a/rust/wolfree_patch_libredirect/src/docusaurus/docs/index.mdx b/rust/wolfree_patch_libredirect/src/docusaurus/docs/index.mdx new file mode 100644 index 0000000..3cefc82 --- /dev/null +++ b/rust/wolfree_patch_libredirect/src/docusaurus/docs/index.mdx @@ -0,0 +1,81 @@ +--- +title: Home page +hide_title: true +slug: / +--- + + + +import FormCTA from "../src/components/FormCTA.tsx"; +import submitMathInputForm from "../src/functions/submitMathInputForm.ts"; +import InputMathProblems from "../src/components/InputMathProblems.tsx"; +import SubmitButton from "../src/components/SubmitButton.tsx"; +import ButtonLink from "../src/components/ButtonLink.tsx"; + +# Wolfree instances that do not bypass paywalls + +Wolfree is a free and open-source software for accessing the calculation results computed by Wolfram Alpha. Wolfree operates through a network of websites known as "instances." Unlike most instances, this instance **does not bypass paywalls**. + + + +## How to access the calculation results generated by Wolfram Alpha + +
+ +1. Type your math problem in the text box. + + + +2. Click the "Compute Input" button. + + + +3. Explore the calculation result provided. 🎉 + + + +## 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. For details about this issue, refer to [issue #425](https://github.com/libredirect/browser_extension/issues/425) on Microsoft GitHub. + +## How this instance resolves the problem + +Unlike most Wolfree instances, this instance prioritizes ethical values and **does not bypass paywalls**. + +## Mirror sites + +Wolfree operates through a network of mirror sites. If you can't access this web page, visit the [mirror sites](/mirror). + + + +## Source code + +Wolfree is **free** and **open-source** software built on transparency and openness, welcoming individuals from diverse backgrounds to collaborate on [source code](/source). ❤️ + + + +## How it works + +1. Install [LibRedirect](https://libredirect.github.io/) on your web browser. +2. Enable auto-redirection from Wolfram to this instance. +3. Enjoy accessing Wolfree instances that **do not bypass paywalls**. + +## Key benefits + +### Compliance with Microsoft GitHub + +This instance **does not bypass paywalls**, resolving [the GitHub issues](https://github.com/libredirect/browser_extension/issues/425) LibRedirect developers encounter. + +### Auto-redirection + +Once you install LibRedirect on your web browser, you can enable auto-redirection from Wolfram to this instance. + +### Cyber Ethics + +By accessing this instance, you actively promote ethical practices and support the work of content creators. + +## Get started now + +Install LibRedirect and enable auto-redirection. Enjoy Wolfree instances that **do not bypass paywalls**. + + diff --git a/rust/wolfree_patch_libredirect/src/docusaurus/docs/mirror.mdx b/rust/wolfree_patch_libredirect/src/docusaurus/docs/mirror.mdx new file mode 100644 index 0000000..a55cd77 --- /dev/null +++ b/rust/wolfree_patch_libredirect/src/docusaurus/docs/mirror.mdx @@ -0,0 +1,24 @@ +--- +title: Mirror site +hide_title: true +--- + + + +# Mirror sites: alternative instances + +Wolfree operates through a network of mirror sites. If you can't access this web page, visit the mirror sites. + +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/ + +## Fetching JSON list of instances + +If you have programming knowledge, you can deserialize the [instances.json](pathname://../instances.json) file. + +## Accessing Wolfree in censored countries + +If you cannot access any of the mirror sites, we recommend installing the [Tor Browser](https://www.torproject.org/) to bypass censorship. diff --git a/rust/wolfree_patch_libredirect/src/docusaurus/docs/source.mdx b/rust/wolfree_patch_libredirect/src/docusaurus/docs/source.mdx new file mode 100644 index 0000000..66e222a --- /dev/null +++ b/rust/wolfree_patch_libredirect/src/docusaurus/docs/source.mdx @@ -0,0 +1,22 @@ +--- +title: Source code +hide_title: true +--- + + + +# Accessing the source code of Wolfree + +Wolfree is **free** and **open-source** software. You can access and download the source code from the following websites: + +1. https://gitea.com/wolfree +2. https://try.gitea.io/wolfree +3. https://codeberg.org/wolfree +4. https://git.disroot.org/wolfree +5. https://next.forgejo.org/wolfree +6. https://git.kiwifarms.net/wolfree +7. http://it7otdanqu7ktntxzm427cba6i53w6wlanlh23v5i3siqmos47pzhvyd.onion/wolfree + +## Accessing the source code in censored countries + +If you cannot access Gitea or Forgejo, we recommend installing the [Tor Browser](https://www.torproject.org/) to bypass censorship. diff --git a/rust/wolfree_patch_libredirect/src/docusaurus/static/instances.json b/rust/wolfree_patch_libredirect/src/docusaurus/static/instances.json new file mode 100644 index 0000000..8cdd008 --- /dev/null +++ b/rust/wolfree_patch_libredirect/src/docusaurus/static/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_patch_libredirect/src/main.rs b/rust/wolfree_patch_libredirect/src/main.rs new file mode 100644 index 0000000..907dc36 --- /dev/null +++ b/rust/wolfree_patch_libredirect/src/main.rs @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ + +//! Customize Wolfree instances to suit Libredirect. + +#![allow(clippy::blanket_clippy_restriction_lints)] +#![allow(clippy::implicit_return)] +#![allow(clippy::question_mark_used)] + +use std::error; +use std::fs; + +/// By default, the main function do nothing as most Wolfree users do not use Libredirect. +#[allow(unreachable_code)] +fn main() -> Result<(), Box> { + // Remove the following line to make the instances Libredirect-compatible. + return Ok(()); + // Remove the previous line to make the instances Libredirect-compatible. + + // Disable the entrypoint of the JavaScript modules. + fs::write( + "./docusaurus/static/ajax/libs/wolfree/2023.8.31/js/entrypoint.js", + "export default () => {};" + )?; + + fs::write( + "./docusaurus/wolfree.config.js", + "module.exports = { config: { libredirect: true } };" + )?; + + fs::write( + "./docusaurus/static/instances.json", + include_str!("./docusaurus/static/instances.json") + )?; + + fs::write("./docusaurus/docs/index.mdx", include_str!("./docusaurus/docs/index.mdx"))?; + fs::write("./docusaurus/docs/mirror.mdx", include_str!("./docusaurus/docs/mirror.mdx"))?; + fs::write("./docusaurus/docs/source.mdx", include_str!("./docusaurus/docs/source.mdx"))?; + + Ok(()) +} diff --git a/rust/wolfree_sed_in_place/Cargo.toml b/rust/wolfree_sed_in_place/Cargo.toml index ab2b32f..0a8bf1d 100644 --- a/rust/wolfree_sed_in_place/Cargo.toml +++ b/rust/wolfree_sed_in_place/Cargo.toml @@ -1,21 +1,24 @@ # 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" +version = "2023.8.31" +authors = [ + "See the commit history of the Git repositories.", + "https://git.kiwifarms.net/wolfree", +] +categories = [ + "command-line-utilities", + "development-tools::build-utils", + "web-programming", + "template-engine", +] edition = "2021" - -authors = ["See the commit history of the Git repositories: "] -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." +keywords = ["rust", "search", "replace", "regular expressions", "regex", "file"] 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 +repository = "https://git.kiwifarms.net/wolfree" +description = "Perform in-place search and replaces operations on all files within specified directories." [dependencies] regex = "1" diff --git a/rust/wolfree_sed_in_place/src/include_str.html b/rust/wolfree_sed_in_place/src/include_str.html index 2fbe0f4..f09b167 100644 --- a/rust/wolfree_sed_in_place/src/include_str.html +++ b/rust/wolfree_sed_in_place/src/include_str.html @@ -1,13 +1,15 @@ + + - + - + + href="/ajax/libs/wolfree/2023.8.31/css/Placeholder.css" /> + href="/ajax/libs/wolfree/2023.8.31/css/PodsParser.css" /> + $0
@@ -72,5 +78,4 @@ $0 Mirror Source -
- \ No newline at end of file + \ No newline at end of file diff --git a/rust/wolfree_sed_in_place/src/include_str.js b/rust/wolfree_sed_in_place/src/include_str.js new file mode 100644 index 0000000..9ef3a31 --- /dev/null +++ b/rust/wolfree_sed_in_place/src/include_str.js @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ + +// @ts-check + +const wolfreeLexicalScopeName = (() => { + /** @type {string[]} */ + const possibleLetters = []; + + 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 = "") => { + 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.warn({ wolfreeLexicalScopeName }); + return ""; + } + + return wolfreeLexicalScopeName; +})(); + +(() => { + const get = (params = "") => { + 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 + */ +// @ts-ignore +$0; + +(async () => { + ( + await import( + // @ts-ignore + "/ajax/libs/wolfree/2023.8.31/js/entrypoint.js" + ) + ).default({ + input: eval(wolfreeLexicalScopeName).value, + ...(eval(wolfreeLexicalScopeName).i2d ? { i2d: true } : {}), + podstate: ["Step-by-step solution", "Step-by-step", "Show all steps"], + }); +})(); diff --git a/rust/wolfree_sed_in_place/src/include_str.tsx b/rust/wolfree_sed_in_place/src/include_str.tsx deleted file mode 100644 index 3c8ff4e..0000000 --- a/rust/wolfree_sed_in_place/src/include_str.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/** - * @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 index 7d56889..f20393f 100644 --- a/rust/wolfree_sed_in_place/src/main.rs +++ b/rust/wolfree_sed_in_place/src/main.rs @@ -1,17 +1,14 @@ -//! The `wolfree_sed_in_place` crate provides a function for performing in-place replacements of patterns in multiple files using regular expressions. +/* SPDX-License-Identifier: AGPL-3.0-or-later */ + +//! This 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. - */ +#![allow(clippy::question_mark_used)] use regex::Regex; +use std::error; use std::fs; use walkdir::WalkDir; @@ -21,94 +18,52 @@ use walkdir::WalkDir; /// 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) +fn sed( + directory_path: &str, + pattern: &str, + replacement: &str +) -> Result<(), Box> { + // Compile the regular expression pattern. + let regex = Regex::new(pattern)?; + // Create a directory walker and filter out non-file entries. + for entry in 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 { + .filter(|entry| !entry.file_type().is_dir()) { 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); - } - }; + // Read the file's contents into a string. + // Perform the regex replacement on the file's contents. + // Write the modified contents back to the file, overwriting its previous contents. + fs::write(file_path, &*regex.replace(&fs::read_to_string(file_path)?, replacement))?; } + Ok(()) } /// 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/", - "", - include_str!("include_str.html"), - ); +/// Demonstrates using `sed` function to perform in-place replacements on files in specific directories. +fn main() -> Result<(), Box> { + sed("./docusaurus/static/input/", "", include_str!("include_str.html"))?; - wolfree_sed_in_place( - "./docusaurus/build/_next/static/chunks/", + sed( + "./docusaurus/static/_next/static/chunks/", r"try(.{0,100}?)generateEncodedJSONFromValue(.*?)unescapeForUrl(.*?)catch(.*?)\{}", - include_str!("include_str.tsx"), - ); + include_str!("include_str.js") + )?; // 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/", + // override the hostname + sed( + "./docusaurus/static/_next/static/chunks/pages/", "window.location.hostname", - "'www.wolframalpha.com'", - ); + "'www.wolframalpha.com'" + )?; + + Ok(()) } // regex101: build, test, and debug regex -- cgit v1.2.3