feat(server): implemented a small preprocessor, that is capable of combining html files

This commit is contained in:
antifallobst 2023-08-24 21:12:50 +02:00
parent 5b78b830a5
commit 5c152593e2
Signed by: antifallobst
GPG Key ID: 2B4F402172791BAF
11 changed files with 1659 additions and 145 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.fleet .fleet
.idea .idea
server/target

View File

@ -1,145 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Nerdcult </title>
<link rel="stylesheet" href="style/topbar.css">
<link rel="stylesheet" href="style/index.css">
</head>
<body>
<header id="header">
<nav id="topbar">
<ul id="tabs-main" class="tabs">
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">Home</tspan></text>
</g></svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">Services</tspan></text>
</g></svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">Community</tspan></text>
</g></svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">About</tspan></text>
</g></svg>
</a></li>
</ul>
<ul id="tabs-account" class="tabs">
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">Sign Up</tspan></text>
</g></svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">Sign In</tspan></text>
</g></svg>
</a></li>
</ul>
</nav>
</header>
<main>
<div class="content">
<ul id="content-boxes">
<li class="content-box">
<p class="content-box-heading">Community</p>
<div class="content-box-data">
<p>
Nerdcult is a platform for (and by) open source
software developers, that aims to make collaboration
as comfortable as possible. We also want to make
it as easy as possible for users to find contributors
for their projects.
Join now by creating an account.
</p>
<ul>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">Explore</tspan></text>
</g></svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">Rules</tspan></text>
</g></svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">Join</tspan></text>
</g></svg>
</a></li>
</ul>
</div>
</li>
<li class="content-box">
<p class="content-box-heading">Tools</p>
<div class="content-box-data">
<p>
We provide tools for software development, communication and project management.
This includes a git server, a matrix homeserver, pads and much more :)
</p>
<ul>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">List</tspan></text>
</g></svg>
</a></li>
</ul>
</div>
</li>
<li class="content-box">
<p class="content-box-heading">Privacy</p>
<div class="content-box-data">
<p>
We save as less personal data as possible and our logs are anonymized.
Your private data, is encrypted with a key that derives from your password.
By that we couldn't sell data and give attackers nothing they could steal.
</p>
<ul>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg" ><g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z" class="tab-svg-path" />
<text x="67.010414" y="31.911449"><tspan class="tab-svg-text">Learn More</tspan></text>
</g></svg>
</a></li>
</ul>
</div>
</li>
</ul>
</div>
</main>
</body>
</html>

1370
server/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

13
server/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "server"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = "4"
env_logger = "0.10"
log = "0.4"
anyhow = "1.0.75"
regex = "1.9.3"

27
server/src/cache.rs Normal file
View File

@ -0,0 +1,27 @@
use anyhow::Result;
use crate::parser;
#[derive(Debug)]
pub struct Sites {
home: String,
// services: String,
// community: String,
// about: String,
// privacy: String,
// blog: String,
}
impl Sites {
pub async fn new(path: &std::path::Path) -> Result<Self> {
std::env::set_current_dir(path)?;
let mut home_file = std::fs::File::open("home.html")?;
Ok(Self {
home: parser::generate_site(&mut home_file)?
})
}
pub fn home(&self) -> &String {
&self.home
}
}

20
server/src/main.rs Normal file
View File

@ -0,0 +1,20 @@
mod cache;
mod parser;
use anyhow::Result;
use log::info;
#[actix_web::main]
async fn main() -> Result<()>{
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
info!("Generating sites");
let sites = cache::Sites::new(&std::path::Path::new("../static/")).await?;
info!("{}", sites.home());
info!("Starting server");
Ok(())
}

27
server/src/parser.rs Normal file
View File

@ -0,0 +1,27 @@
use std::io::{Read, read_to_string};
use anyhow::{Error, Result};
use log::{error, info};
pub fn generate_site(base: &mut std::fs::File) -> Result<String> {
let include_regex = regex::Regex::new("\\s+@@@include ((?:[^\\/]*\\/)*)(.*)@@@")?;
let mut content = String::new();
base.read_to_string(&mut content)?;
let mut lines = Vec::new();
for line in content.lines() {
if include_regex.is_match(line) {
info!("Regex found: {}", line);
let mut parts = line.split([' ', '\t', '@']).collect::<Vec<&str>>();
parts.retain(|&x| !x.is_empty());
let mut file = std::fs::File::open(parts.get(1).expect("This should never happen due to the regex check."))?;
lines.push(generate_site(&mut file)?);
} else {
lines.push(line.to_owned());
}
}
Ok(lines.join("\n"))
}

124
static/home.html Normal file
View File

@ -0,0 +1,124 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Nerdcult </title>
<link rel="stylesheet" href="style/topbar.css">
<link rel="stylesheet" href="style/home.css">
</head>
<body>
<header id="header">
@@@include topbar.html@@@
</header>
<main>
<div class="content">
<ul id="content-boxes">
<li class="content-box">
<p class="content-box-heading">Community</p>
<div class="content-box-data">
<p>
Nerdcult is a platform for (and by) open source
software developers, that aims to make collaboration
as comfortable as possible. We also want to make
it as easy as possible for users to find contributors
for their projects.
Join now by creating an account.
</p>
<ul>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">Explore</tspan>
</text>
</g>
</svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">Rules</tspan>
</text>
</g>
</svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">Join</tspan>
</text>
</g>
</svg>
</a></li>
</ul>
</div>
</li>
<li class="content-box">
<p class="content-box-heading">Tools</p>
<div class="content-box-data">
<p>
We provide tools for software development, communication and project management.
This includes a git server, a matrix homeserver, pads and much more :)
</p>
<ul>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">List</tspan>
</text>
</g>
</svg>
</a></li>
</ul>
</div>
</li>
<li class="content-box">
<p class="content-box-heading">Privacy</p>
<div class="content-box-data">
<p>
We save as less personal data as possible and our logs are anonymized.
Your private data, is encrypted with a key that derives from your password.
By that we couldn't sell data and give attackers nothing they could steal.
</p>
<ul>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">Learn More</tspan>
</text>
</g>
</svg>
</a></li>
</ul>
</div>
</li>
</ul>
</div>
</main>
</body>
</html>

77
static/topbar.html Normal file
View File

@ -0,0 +1,77 @@
<nav id="topbar">
<ul id="tabs-main" class="tabs">
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">Home</tspan>
</text>
</g>
</svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">Services</tspan>
</text>
</g>
</svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">Community</tspan>
</text>
</g>
</svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">About</tspan>
</text>
</g>
</svg>
</a></li>
</ul>
<ul id="tabs-account" class="tabs">
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">Sign Up</tspan>
</text>
</g>
</svg>
</a></li>
<li><a href="#">
<svg width="136" height="54" viewBox="-0.5 -0.5 136 54" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m 123.5,11.5 5,5 c 3.33333,3.333333 5,8.333333 5,15 v 10 c 0,6.666667 -3.33333,10 -10,10 H 11.500001 c -6.6666667,0 -10,-3.333333 -10,-10 v -30 c 0,-6.6666666 3.3333333,-9.9999996 10,-9.9999996 H 103.5 c 6.66667,0 11.66667,1.666667 15,5 z"
class="tab-svg-path"/>
<text x="67.010414" y="31.911449">
<tspan class="tab-svg-text">Sign In</tspan>
</text>
</g>
</svg>
</a></li>
</ul>
</nav>