summaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorname <email@example.com>2023-09-27 13:34:23 +0200
committername <email@example.com>2023-09-27 13:34:23 +0200
commit72d8b4e6bee0ffac79e96dd649a9da2adb86b507 (patch)
tree8d1f37e5d88a598675b1a65128c35323c99825f5 /rust
parentMerge pull request 'Please consider adding my instance' (#2) from superprivacy/wolfree-dockerfile:main into main (diff)
downloadwolfree-dockerfile-72d8b4e6bee0ffac79e96dd649a9da2adb86b507.tar
wolfree-dockerfile-72d8b4e6bee0ffac79e96dd649a9da2adb86b507.tar.gz
wolfree-dockerfile-72d8b4e6bee0ffac79e96dd649a9da2adb86b507.tar.bz2
wolfree-dockerfile-72d8b4e6bee0ffac79e96dd649a9da2adb86b507.tar.lz
wolfree-dockerfile-72d8b4e6bee0ffac79e96dd649a9da2adb86b507.tar.xz
wolfree-dockerfile-72d8b4e6bee0ffac79e96dd649a9da2adb86b507.tar.zst
wolfree-dockerfile-72d8b4e6bee0ffac79e96dd649a9da2adb86b507.zip
Diffstat (limited to 'rust')
-rw-r--r--rust/wolfree_download_dependencies/Cargo.toml20
-rw-r--r--rust/wolfree_download_dependencies/src/main.rs22
-rw-r--r--rust/wolfree_libredirect_patch/Cargo.toml21
-rw-r--r--rust/wolfree_libredirect_patch/src/body.md68
-rw-r--r--rust/wolfree_libredirect_patch/src/head.html43
-rw-r--r--rust/wolfree_libredirect_patch/src/main.rs95
-rw-r--r--rust/wolfree_patch_libredirect/Cargo.toml28
-rw-r--r--rust/wolfree_patch_libredirect/src/docusaurus/docs/index.mdx81
-rw-r--r--rust/wolfree_patch_libredirect/src/docusaurus/docs/mirror.mdx24
-rw-r--r--rust/wolfree_patch_libredirect/src/docusaurus/docs/source.mdx22
-rw-r--r--rust/wolfree_patch_libredirect/src/docusaurus/static/instances.json (renamed from rust/wolfree_libredirect_patch/src/instances.json)0
-rw-r--r--rust/wolfree_patch_libredirect/src/main.rs40
-rw-r--r--rust/wolfree_sed_in_place/Cargo.toml25
-rw-r--r--rust/wolfree_sed_in_place/src/include_str.html17
-rw-r--r--rust/wolfree_sed_in_place/src/include_str.js (renamed from rust/wolfree_sed_in_place/src/include_str.tsx)24
-rw-r--r--rust/wolfree_sed_in_place/src/main.rs113
16 files changed, 305 insertions, 338 deletions
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
+//! <https://stackoverflow.com/questions/42130132/can-cargo-download-and-build-dependencies-without-also-building-the-application>
+//!
+//! cargo build --dependencies-only · Issue #2644 · rust-lang/cargo · GitHub
+//! <https://github.com/rust-lang/cargo/issues/2644>
+
+#![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<dyn error::Error>> {
+ 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: <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
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 @@
-<!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/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",
- "<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_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: /
+---
+
+<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
+
+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**.
+
+<FormCTA autoFocus={true} submitText="Compute Input" />
+
+## How to access the calculation results generated by Wolfram Alpha
+
+<form onSubmit={submitMathInputForm}>
+
+1. Type your math problem in the text box.
+
+ <InputMathProblems autoFocus={false} defaultValue="y'=y" />
+
+2. Click the "Compute Input" button.
+
+ <SubmitButton text="Compute Input" />
+
+3. Explore the calculation result provided. 🎉
+
+</form>
+
+## 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).
+
+<ButtonLink to="./mirror" text="Access mirror sites" />
+
+## 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). ❤️
+
+<ButtonLink to="./source" text="Explore source code" />
+
+## 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**.
+
+<ButtonLink to="https://libredirect.github.io/" text="Install LibRedirect" />
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
+---
+
+<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
+
+# 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
+---
+
+<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
+
+# 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_libredirect_patch/src/instances.json b/rust/wolfree_patch_libredirect/src/docusaurus/static/instances.json
index 8cdd008..8cdd008 100644
--- a/rust/wolfree_libredirect_patch/src/instances.json
+++ b/rust/wolfree_patch_libredirect/src/docusaurus/static/instances.json
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<dyn error::Error>> {
+ // 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: <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."
+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 @@
+<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
+
<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/jquery/3.7.1/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>
+<script type="module" src="/ajax/libs/wolfree/2023.8.31/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" />
+ href="/ajax/libs/wolfree/2023.8.31/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" />
+ href="/ajax/libs/wolfree/2023.8.31/css/PodsParser.css" />
<style>
html>body>#__next>div>header {
@@ -64,6 +66,10 @@
}
</style>
+<!--
+ Regex in regex - Rust
+ https://docs.rs/regex/latest/regex/struct.Regex.html#replacement-string-syntax
+-->
$0
<header>
@@ -72,5 +78,4 @@ $0
<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
+</header> \ 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.js
index 3c8ff4e..9ef3a31 100644
--- a/rust/wolfree_sed_in_place/src/include_str.tsx
+++ b/rust/wolfree_sed_in_place/src/include_str.js
@@ -1,14 +1,10 @@
-/**
- * @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.
- */
+/* SPDX-License-Identifier: AGPL-3.0-or-later */
// @ts-check
const wolfreeLexicalScopeName = (() => {
- const possibleLetters = Array();
+ /** @type {string[]} */
+ const possibleLetters = [];
for (let i = 32; i < 127; i++) {
possibleLetters.push(String.fromCharCode(i));
@@ -18,7 +14,7 @@ const wolfreeLexicalScopeName = (() => {
possibleLetters.map((y) => x + y)
);
- const isValid = (name = String()) => {
+ const isValid = (name = "") => {
try {
return (
typeof eval(name).value === "string" &&
@@ -32,7 +28,7 @@ const wolfreeLexicalScopeName = (() => {
const wolfreeLexicalScopeName = possibleNames.find(isValid);
if (typeof wolfreeLexicalScopeName !== "string") {
- console.error({ wolfreeLexicalScopeName });
+ console.warn({ wolfreeLexicalScopeName });
return "";
}
@@ -40,7 +36,7 @@ const wolfreeLexicalScopeName = (() => {
})();
(() => {
- const get = (params = String()) => {
+ const get = (params = "") => {
return new URLSearchParams(location.search).get(params);
};
@@ -51,8 +47,6 @@ const wolfreeLexicalScopeName = (() => {
/**
* 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;
@@ -61,11 +55,11 @@ $0;
(
await import(
// @ts-ignore
- "../../../ajax/libs/wolfree/23.7.8/js/Entrypoint.js"
+ "/ajax/libs/wolfree/2023.8.31/js/entrypoint.js"
)
).default({
input: eval(wolfreeLexicalScopeName).value,
- i2d: eval(wolfreeLexicalScopeName).i2d,
- extraPodstates: [],
+ ...(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/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<dyn error::Error>> {
+ // 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/",
- "</head><body>",
- include_str!("include_str.html"),
- );
+/// Demonstrates using `sed` function to perform in-place replacements on files in specific directories.
+fn main() -> Result<(), Box<dyn error::Error>> {
+ sed("./docusaurus/static/input/", "</head><body>", 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