diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml
new file mode 100644
index 0000000..9875293
--- /dev/null
+++ b/.github/workflows/gh-pages.yml
@@ -0,0 +1,53 @@
+
+name: Deploy website on GitHub Pages
+
+on:
+ # Runs on pushes targeting the default branch
+ push:
+ branches: ["main"]
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
+permissions:
+ contents: read
+ pages: write
+ id-token: write
+
+# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
+# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
+concurrency:
+ group: "pages"
+ cancel-in-progress: false
+
+jobs:
+ # Build job
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Setup Pages
+ uses: actions/configure-pages@v3
+ - uses: actions-rust-lang/setup-rust-toolchain@v1
+ - name: Generate HTML
+ run: cargo run --release
+ - name: Copy bundle.css
+ run: cp ./target/csm/bundle.css dist/
+ - name: Upload artifact
+ uses: actions/upload-pages-artifact@v2
+ with:
+ path: dist/
+
+ # Deployment job
+ deploy:
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+ runs-on: ubuntu-latest
+ needs: build
+ steps:
+ - name: Deploy to GitHub Pages
+ id: deployment
+ uses: actions/deploy-pages@v2
diff --git a/Cargo.toml b/Cargo.toml
index 07e75ef..9f72bf0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,6 +5,9 @@ members = [
"rscx-macros",
"benches",
]
+exclude = [
+ "website",
+]
[workspace.package]
version = "0.1.9"
diff --git a/website/.gitignore b/website/.gitignore
new file mode 100644
index 0000000..320e434
--- /dev/null
+++ b/website/.gitignore
@@ -0,0 +1,3 @@
+target
+Cargo.lock
+dist/
diff --git a/website/Cargo.toml b/website/Cargo.toml
new file mode 100644
index 0000000..ae7fc81
--- /dev/null
+++ b/website/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "website"
+edition = "2021"
+version = "0.1.0"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+async-recursion = "1.0.5"
+csm = { git = "https://github.com/Pitasi/csm", version = "0.1.0" }
+rscx = "0.1.9"
+rscx-mdx = "0.1.3"
+tokio = { version = "1.32.0", features = ["full"] }
diff --git a/website/README.md b/website/README.md
new file mode 100644
index 0000000..cb7cdd4
--- /dev/null
+++ b/website/README.md
@@ -0,0 +1,15 @@
+# website
+
+Static site generator for https://rscx.dev.
+
+It uses rscx (duh), [https://github.com/Pitasi/rscx-mdx](rscx-mdx) for writing
+markdown and [https://github.com/Pitasi/csm](csm) for scoped CSS styling.
+
+
+## Build the site
+
+Install [https://github.com/casey/just](just) and run:
+
+```sh
+just build
+```
diff --git a/website/justfile b/website/justfile
new file mode 100644
index 0000000..58b6aae
--- /dev/null
+++ b/website/justfile
@@ -0,0 +1,12 @@
+dev:
+ static-web-server --port 8787 --root ./dist &
+ open http://localhost:8787
+ cargo watch -i dist/ -s "cargo run && just copy-bundle-css"
+
+build-release: build-html-release copy-bundle-css
+
+build-html-release:
+ cargo run --release
+
+copy-bundle-css:
+ cp ./target/csm/bundle.css ./dist/bundle.css
diff --git a/website/pages/index.md b/website/pages/index.md
new file mode 100644
index 0000000..d8686f7
--- /dev/null
+++ b/website/pages/index.md
@@ -0,0 +1,2 @@
+# rscx 🪶
+
diff --git a/website/pages/subfolder/index.md b/website/pages/subfolder/index.md
new file mode 100644
index 0000000..ba25b1c
--- /dev/null
+++ b/website/pages/subfolder/index.md
@@ -0,0 +1 @@
+# testing subfolders :)
diff --git a/website/src/main.rs b/website/src/main.rs
new file mode 100644
index 0000000..77e7a6e
--- /dev/null
+++ b/website/src/main.rs
@@ -0,0 +1,82 @@
+use std::{
+ fs::{self, File},
+ io::{Read, Write},
+ path::Path,
+};
+
+use csm::csm;
+use rscx::{component, html, EscapeAttribute};
+use rscx_mdx::mdx::{Mdx, MdxComponentProps};
+
+#[tokio::main]
+async fn main() {
+ let pages_dir = Path::new("pages");
+ let dist_dir = Path::new("dist");
+ let _ = fs::remove_dir_all(&dist_dir);
+ render(&pages_dir, &dist_dir).await;
+}
+
+#[async_recursion::async_recursion]
+async fn render(dir: &Path, dist_dir: &Path) {
+ fs::create_dir_all(&dist_dir).unwrap();
+
+ for entry in dir.read_dir().unwrap() {
+ let entry = entry.unwrap();
+ let path = entry.path();
+
+ if entry.file_type().unwrap().is_dir() {
+ render(&path, &dist_dir.join(entry.file_name())).await;
+ continue;
+ }
+
+ let file_name = path.file_name().unwrap().to_str().unwrap();
+ if !file_name.ends_with(".md") {
+ continue;
+ }
+
+ println!("building {}", path.as_path().display());
+ let file_name = file_name.trim_end_matches(".md");
+
+ let mut file = File::open(&path).unwrap();
+ let mut contents = String::new();
+ file.read_to_string(&mut contents).unwrap();
+ let mut file = File::create(dist_dir.join(format!("{}.html", file_name))).unwrap();
+
+ let html = render_markdown(contents).await;
+ file.write_all(html.as_bytes()).unwrap();
+ }
+}
+
+async fn render_markdown(md: String) -> String {
+ html! {
+