From 9dedbeb1e5c69dab549e63dd7c805d6f55071d33 Mon Sep 17 00:00:00 2001 From: Killian O'Gorman <83577130+killianogorman@users.noreply.github.com> Date: Sat, 8 Jun 2024 17:39:36 +0100 Subject: [PATCH] Creat Blog Config and Add profanity checker --- .github/workflows/check.yml | 68 ++++++++++++++++++++++++++++++++++ Cargo.toml | 12 ++++++ src/content/config.ts | 15 ++++++++ src/layouts/Post.astro | 55 +++++++++++++++++++++++++++ src/main.rs | 59 +++++++++++++++++++++++++++++ src/pages/blog/[...slug].astro | 28 ++++++++++++++ src/pages/blog/index.astro | 50 +++++++++++++++++++++++++ 7 files changed, 287 insertions(+) create mode 100644 .github/workflows/check.yml create mode 100644 Cargo.toml create mode 100644 src/layouts/Post.astro create mode 100644 src/main.rs create mode 100644 src/pages/blog/[...slug].astro create mode 100644 src/pages/blog/index.astro diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..cc02fb2 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,68 @@ +name: Check Markdown and Text files for profanity +on: + push: + paths: + - "**.md" + - "**.mdx" + - "**.json" + branches: + - main + +jobs: + setup_environment: + runs-on: ubuntu-latest + name: Set up Environment + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Set up cargo cache + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + get_changed_files: + runs-on: ubuntu-latest + name: Get Changed Files + steps: + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v44 + - name: List all changed files + env: + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + for file in ${ALL_CHANGED_FILES}; do + echo "$file was changed" + done + + run_profanity_check: + needs: [setup_environment, get_changed_files] + runs-on: ubuntu-latest + name: Run Profanity Check + steps: + - name: Install rust dependencies & build + run: | + cargo build --release + - name: Run Profanity Check + env: + ALL_CHANGED_FILES: ${{ needs.get_changed_files.outputs.all_changed_files }} + run: | + for file in ${ALL_CHANGED_FILES}; do + echo "Checking file: $file" + cargo run --release -- "$file" + done diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..71fa00b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "website" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +reqwest = {version = "0.12.4",features = ['json']} +tokio = {version = "1.38.0",features = ['full']} +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" \ No newline at end of file diff --git a/src/content/config.ts b/src/content/config.ts index 6e38239..03e239a 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -35,8 +35,23 @@ const peopleCollection = defineCollection({ }), }), }); +const postsCollection = defineCollection({ + type: 'content', + schema: z.object({ + title: z.string(), + pubDate: z.date(), + description: z.string(), + author: z.string(), + image: z.object({ + url: z.string(), + alt: z.string() + }), + tags: z.array(z.string()) + }) +}); export const collections = { talks: talksCollection, people: peopleCollection, + blog: postsCollection }; diff --git a/src/layouts/Post.astro b/src/layouts/Post.astro new file mode 100644 index 0000000..9ebca8d --- /dev/null +++ b/src/layouts/Post.astro @@ -0,0 +1,55 @@ +--- +import Layout from "./Layout.astro"; +--- + +
+
+
+

{author}

+

{title}

+

{description}

+
+ { + // bg-pink px-5 py-3 rounded-full font-black drop-shadow-[3px_4px_rgba(0,0,0,1)] + tags.map((tag) => ( + + {tag} + + )) + } +
+
+
+ +
+
+
+

{pubDate.toDateString()}

+

{author}

+
+
+
+
+ + { + headings && headings.length > 0 && ( + + ) + } +
+
+
+
+ \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..f385d48 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,59 @@ +use reqwest::Client; +use serde::{Deserialize, Serialize}; +use serde_json::json; +use std::{fs, path::Path}; + +#[derive(Serialize, Deserialize, Debug)] +struct Address { + #[serde(rename = "isProfanity")] + is_profanity: bool, + score: f64, +} +#[tokio::main] +async fn main() { + let args: Vec = std::env::args().collect(); + println!("{}", args.join("\n Newline: \n ")); + + let current_dir = std::env::current_dir().unwrap(); + println!("{}", current_dir.display()); + for filename in &args[1..] { + let p = format!("{}/{}", current_dir.display(), filename); + println!("{}", p); + let path = Path::new(&p); + let abs_path = fs::canonicalize(&path).unwrap(); + println!("Checking file: {:?}", abs_path); + + if path.is_file() { + let content = fs::read_to_string(&path).unwrap(); + println!("{content}"); + let char_chunks = split_into_chunks(&content, 32); + + for chunk in char_chunks { + let contains_profanity = check_profanity(&chunk).await; + if contains_profanity { + println!("Profanity found in file: {:?}, chunk: {:?}", path, chunk); + std::process::exit(1); + } + } + } + } +} +fn split_into_chunks(text: &String, chunk_size: usize) -> Vec { + text.split_whitespace() + .collect::>() + .chunks(chunk_size) + .map(|chunk| chunk.join(" ")) + .collect() +} +async fn check_profanity(text: &String) -> bool { + let client = Client::new(); + let res = client + .post("https://vector.profanity.dev") + .json(&json!({"message": text})) + .send() + .await + .unwrap() + .json::
() + .await; + res.unwrap().is_profanity +} \ No newline at end of file diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro new file mode 100644 index 0000000..93e2ebb --- /dev/null +++ b/src/pages/blog/[...slug].astro @@ -0,0 +1,28 @@ +--- +import { getCollection } from 'astro:content'; +import Talk from '../../layouts/Talk.astro'; + +export async function getStaticPaths() { + const blogEntries = await getCollection('blog'); + return blogEntries.map(entry => ({ + params: { slug: entry.slug }, props: { entry }, + })); +} + +const { entry } = Astro.props; +const { Content } = await entry.render(); +--- + + + \ No newline at end of file diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro new file mode 100644 index 0000000..12eb4be --- /dev/null +++ b/src/pages/blog/index.astro @@ -0,0 +1,50 @@ +--- +import { getCollection } from "astro:content"; +import Layout from "../../layouts/Layout.astro"; +const allPosts = await getCollection('blog'); +--- + + +
+
+

Talks Archive

+

Here is all the info relating to talks done for Rust dublin.

+

Each talk is organized by date and speaker, with links to slides, videos, and other resources where available. Browse through our catalog to discover insightful discussions and deep dives into various Rust topics presented by our community members.

+ +
+ +
+