Import cursed.graphics SRC
This commit is contained in:
parent
66528d6284
commit
3706d904b3
35
.github/workflows/deploy-cursed-graphics.yml
vendored
Normal file
35
.github/workflows/deploy-cursed-graphics.yml
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
name: Deploy cursed.graphics
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths:
|
||||||
|
- 'sites/cursed.graphics/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
name: Production Deployment
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: production
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
deployments: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout master
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Ensure Cargo is installed
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Build Edge Worker
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
environment: production
|
||||||
|
workingDirectory: sites/cursed.graphics
|
@ -1,2 +1,5 @@
|
|||||||
# Global owners
|
# Global owners
|
||||||
* @ewpratten
|
* @ewpratten
|
||||||
|
|
||||||
|
# Projects
|
||||||
|
sites/cursed.graphics/* @ewpratten @exvacuum @hyperliskdev @percyx42 @demilurii
|
@ -7,8 +7,8 @@ build_search_index = true
|
|||||||
generate_feeds = true
|
generate_feeds = true
|
||||||
feed_filenames = ["rss.xml"]
|
feed_filenames = ["rss.xml"]
|
||||||
minify_html = false # This breaks mermaid diagrams :(
|
minify_html = false # This breaks mermaid diagrams :(
|
||||||
ignored_content = ["content/@/blog/*.md"]
|
ignored_content = ["content/@/blog/*.md", "sites/"]
|
||||||
ignored_static = ["static/images/drawings/*/*.xcf"]
|
ignored_static = ["static/images/drawings/*/*.xcf", "sites/"]
|
||||||
|
|
||||||
[markdown]
|
[markdown]
|
||||||
highlight_code = true
|
highlight_code = true
|
||||||
|
2
sites/README.txt
Normal file
2
sites/README.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
This is the new area for storing site SRCs.
|
||||||
|
The main website shall move here soon.
|
26
sites/cursed.graphics/.gitignore
vendored
Normal file
26
sites/cursed.graphics/.gitignore
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
|
|
||||||
|
# Node
|
||||||
|
/build
|
||||||
|
/node_modules
|
||||||
|
/.wrangler
|
18
sites/cursed.graphics/Cargo.toml
Normal file
18
sites/cursed.graphics/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[package]
|
||||||
|
name = "cursed-graphics"
|
||||||
|
publish = false
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
getrandom = { version = "0.2.15", features = ["js"] }
|
||||||
|
worker = "0.4.2"
|
||||||
|
worker-macros = "0.4.2"
|
||||||
|
console_error_panic_hook = "0.1.7"
|
||||||
|
rand = "0.8.5"
|
||||||
|
base64 = "0.22.1"
|
||||||
|
|
||||||
|
[package.metadata.wasm-pack.profile.release]
|
||||||
|
wasm-opt = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
70
sites/cursed.graphics/src/lib.rs
Normal file
70
sites/cursed.graphics/src/lib.rs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
use worker::*;
|
||||||
|
|
||||||
|
#[event(fetch)]
|
||||||
|
async fn fetch(request: Request, env: Env, _context: Context) -> Result<Response> {
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
|
// Split the path into segments
|
||||||
|
let url = request.url().unwrap();
|
||||||
|
let path_segments = url.path_segments();
|
||||||
|
|
||||||
|
// Handle the sub-paths
|
||||||
|
match path_segments {
|
||||||
|
Some(path_segments) => match path_segments.collect::<Vec<&str>>().as_slice() {
|
||||||
|
// Index
|
||||||
|
[""] => Response::from_html(include_str!("../templates/index.html")),
|
||||||
|
|
||||||
|
// Randomizer
|
||||||
|
["random"] => {
|
||||||
|
// List the images in the bucket
|
||||||
|
let images = env.bucket("IMAGES")?.list().execute().await?.objects();
|
||||||
|
|
||||||
|
// If there's a referer header, make note of the previous image
|
||||||
|
let previous_image = request.headers().get("Referer")?.map(|referer| {
|
||||||
|
let referer = referer.split("/").last().unwrap();
|
||||||
|
referer.to_string()
|
||||||
|
});
|
||||||
|
|
||||||
|
// Pick a random file name. Don't pick the same one as the previous image
|
||||||
|
let images = images.iter().filter(|image| {
|
||||||
|
let image_id = image.key().split(".").next().unwrap().to_string();
|
||||||
|
previous_image != Some(image_id)
|
||||||
|
}).collect::<Vec<_>>();
|
||||||
|
let random_index = rand::random::<usize>() % images.len();
|
||||||
|
let random_image = images.get(random_index).unwrap().key();
|
||||||
|
let random_image = random_image.split(".").next().unwrap();
|
||||||
|
|
||||||
|
Response::builder()
|
||||||
|
.with_status(302)
|
||||||
|
.with_header("Location", &format!("/{}", random_image))?
|
||||||
|
.ok("")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Image subpage (addressed by numeric ID)
|
||||||
|
[id] => {
|
||||||
|
// List the images in the bucket
|
||||||
|
let images = env.bucket("IMAGES")?.list().execute().await?.objects();
|
||||||
|
|
||||||
|
// Find the first one with a matching name
|
||||||
|
let image = images.iter().find(|image| {
|
||||||
|
image.key().split(".").next().unwrap() == *id
|
||||||
|
});
|
||||||
|
|
||||||
|
// If no result is found, this image doesn't exist
|
||||||
|
if image.is_none() {
|
||||||
|
return Response::error("Not Found", 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serve the image
|
||||||
|
Response::from_html(format!(
|
||||||
|
include_str!("../templates/image.html"),
|
||||||
|
image_id = id,
|
||||||
|
image_filename = image.unwrap().key()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => Response::error("Not Found", 404),
|
||||||
|
},
|
||||||
|
_ => Response::error("Not Found", 404),
|
||||||
|
}
|
||||||
|
}
|
54
sites/cursed.graphics/templates/image.html
Normal file
54
sites/cursed.graphics/templates/image.html
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Cursed Graphics: {image_id}</title>
|
||||||
|
<link rel="icon" href="https://raw.cursed.graphics/0.png" type="image/x-icon">
|
||||||
|
|
||||||
|
<meta property="og:type" content="website">
|
||||||
|
<meta property="og:title" content="Cursed Graphics: {image_id}">
|
||||||
|
<meta property="og:url" content="https://cursed.graphics/{image_id}">
|
||||||
|
<meta property="og:image" content="https://raw.cursed.graphics/{image_filename}">
|
||||||
|
|
||||||
|
<meta name="twitter:card" content="summary_large_image">
|
||||||
|
<meta property="twitter:domain" content="cursed.graphics">
|
||||||
|
<meta property="twitter:url" content="https://cursed.graphics/{image_id}">
|
||||||
|
<meta name="twitter:title" content="Cursed Graphics: {image_id}">
|
||||||
|
<meta name="twitter:image" content="https://raw.cursed.graphics/{image_filename}">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body {{
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
min-height: 100vh;
|
||||||
|
width: 100vw;
|
||||||
|
|
||||||
|
font-family: sans-serif;
|
||||||
|
background-color: #eeeded;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}}
|
||||||
|
|
||||||
|
main>img {{
|
||||||
|
display: block;
|
||||||
|
margin: auto;
|
||||||
|
max-width: calc(min(800px, 90vw));
|
||||||
|
max-height: calc(min(800px, 85vh));
|
||||||
|
border: 5px solid black;
|
||||||
|
}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main style="margin: 1em; text-align: center;">
|
||||||
|
<img src="https://raw.cursed.graphics/{image_filename}" alt="{image_id}">
|
||||||
|
<a href="/random" style="display: block; margin-top: 1em; text-decoration: none;">More</a>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script data-goatcounter="https://cursed-graphics.goatcounter.com/count"
|
||||||
|
async src="//gc.zgo.at/count.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
45
sites/cursed.graphics/templates/index.html
Normal file
45
sites/cursed.graphics/templates/index.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Cursed Graphics</title>
|
||||||
|
<link rel="icon" href="https://raw.cursed.graphics/0.png" type="image/x-icon">
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:title" content="Cursed Graphics" />
|
||||||
|
<meta property="og:url" content="https://cursed.graphics" />
|
||||||
|
<meta property="og:image" content="https://raw.cursed.graphics/0.png" />
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
min-height: 100vh;
|
||||||
|
width: 100vw;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
text-align: center;
|
||||||
|
max-width: 800px;
|
||||||
|
width: 100%;
|
||||||
|
font-size: x-large;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
window.location.replace("/random");
|
||||||
|
</script>
|
||||||
|
<main>
|
||||||
|
<h1>Cursed Graphics</h1>
|
||||||
|
<a href="/random">Show Me</a>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
11
sites/cursed.graphics/wrangler.toml
Normal file
11
sites/cursed.graphics/wrangler.toml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
name = "cursed-graphics"
|
||||||
|
main = "build/worker/shim.mjs"
|
||||||
|
compatibility_date = "2024-11-23"
|
||||||
|
|
||||||
|
[[r2_buckets]]
|
||||||
|
binding = "IMAGES"
|
||||||
|
bucket_name = "cursed-graphics"
|
||||||
|
preview_bucket_name = "cursed-graphics"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
command = "cargo install worker-build && worker-build --release"
|
Loading…
x
Reference in New Issue
Block a user