forked from rust-dublin/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creat Blog Config and Add profanity checker
- Loading branch information
1 parent
619acc8
commit 9dedbeb
Showing
7 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
import Layout from "./Layout.astro"; | ||
--- | ||
<Layout title={title} description={description} keywords=""> | ||
<main class="pt-16 px-12 sm:px-28 text-lg"> | ||
<section class="flex flex-col sm:flex-row justify-between gap-12 pt-16 sm:pt-32 pb-16"> | ||
<div class="sm:w-[55%] pr-11"> | ||
<p class="font-semibold">{author}</p> | ||
<h1 class="font-alfa-slab text-3xl sm:text-4xl">{title}</h1> | ||
<p>{description}</p> | ||
<div | ||
class="pt-3 pb-2 flex gap-3 text-sm uppercase w-full overflow-hidden flex-wrap" | ||
> | ||
{ | ||
// bg-pink px-5 py-3 rounded-full font-black drop-shadow-[3px_4px_rgba(0,0,0,1)] | ||
tags.map((tag) => ( | ||
<a | ||
href={`/talks?tags=[${tag}]`} | ||
class=" py-1 px-3 border-blk border-[1.4px] rounded-full hover:bg-yeller hover:text-blk hover:drop-shadow-[3px_4px_rgba(0,0,0,1)] transition-all" | ||
> | ||
{tag} | ||
</a> | ||
)) | ||
} | ||
</div> | ||
</div> | ||
<div> | ||
<iframe | ||
id="ytplayer" | ||
width="222" | ||
class=" w-full sm:w-96 h-48 relative drop-shadow-[6px_7px_rgba(0,0,0,1)] rounded-md" | ||
src={makeYTurl(video_url)}></iframe> | ||
</div> | ||
</section> | ||
<section class=" pt-5 border-t-[1px] border-dashed border-blk flex justify-around"> | ||
<p>{pubDate.toDateString()}</p> | ||
<p>{author}</p> | ||
</section> | ||
<section class="flex pt-32"> | ||
<div class=" flex flex-wrap w-full"><slot /></div> | ||
<div> | ||
<!-- Table of Contents --> | ||
{ | ||
headings && headings.length > 0 && ( | ||
<nav class="article-toc"> | ||
<h3>Table of Content</h3> | ||
<TableOfContents headings={headings} /> | ||
</nav> | ||
) | ||
} | ||
</div> | ||
</section> | ||
</main> | ||
</Layout> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> = 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<String> { | ||
text.split_whitespace() | ||
.collect::<Vec<&str>>() | ||
.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::<Address>() | ||
.await; | ||
res.unwrap().is_profanity | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
--- | ||
<Talk | ||
title={entry.data.title} | ||
description={entry.data.description} | ||
author={entry.data.author} | ||
tags={entry.data.tags} | ||
image={entry.data.image} | ||
event_location={''} | ||
video_url={''} | ||
slides_url={''} | ||
headings={[]} | ||
pubDate={entry.data.pubDate} | ||
> | ||
<Content/> | ||
</Talk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
import { getCollection } from "astro:content"; | ||
import Layout from "../../layouts/Layout.astro"; | ||
const allPosts = await getCollection('blog'); | ||
--- | ||
|
||
<Layout title="" description="" keywords=""> | ||
<main class="pt-36 px-16 lg:px-60 pb-16 min-h-[55vh] w-full text-blk"> | ||
<div class="w-full border-b-[1px] border-dashed border-blk pb-6 mb-8"> | ||
<h1 class="text-4xl sm:text-7xl font-alfa-slab pb-4">Talks Archive</h1> | ||
<p>Here is all the info relating to talks done for Rust dublin.</p> | ||
<p>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.</p> | ||
<aside class="pt-3">Done a talk? Not Listed? If your talk isnt listed please go to <a href="https://gihub.com/rust-dublin/website" class=" underline">gihub.com/rust-dublin/website</a> and open a pull request.</aside> | ||
</div> | ||
<div class="w-full flex flex-col gap-8"> | ||
{ | ||
allPosts.reverse().map((e) => { | ||
return ( | ||
<a class="p-9 w-full px-5 border-blk border-[1.4px] bg-wh hover:drop-shadow-[3px_4px_rgba(0,0,0,1)] transition-all duration-150" href={"/blog/" + e.slug}> | ||
<article class="w-full" title={e.data.title}> | ||
{/* Top Bar */} | ||
<div class="flex items-center pb-8 gap-3"> | ||
<div class="pt-3 pb-2 flex gap-3 text-sm uppercase w-full overflow-hidden flex-wrap"> | ||
{e.data.tags.slice(1,4).map((v) => { | ||
return ( | ||
<div class=" py-1 px-3 border-blk border-[1.4px] rounded-full hover:bg-yeller hover:text-blk hover:drop-shadow-[3px_4px_rgba(0,0,0,1)] transition-all"> | ||
{v} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
<h3> | ||
<span>{e.data.pubDate.toLocaleDateString()}</span> | ||
</h3> | ||
</div> | ||
{/* Title Description */} | ||
<div class="flex flex-col"> | ||
<h1 class="text-2xl sm:text-4xl pb-3 font-alfa-slab">{e.data.title}</h1> | ||
<p>{e.data.description}</p> | ||
</div> | ||
{/* Author */} | ||
<div></div> | ||
</article> | ||
</a> | ||
); | ||
}) | ||
} | ||
</div> | ||
</main> | ||
</Layout> |