-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial version of github pages website
- Loading branch information
Showing
9 changed files
with
184 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,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 |
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,3 @@ | ||
target | ||
Cargo.lock | ||
dist/ |
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,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"] } |
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,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 | ||
``` |
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 @@ | ||
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 |
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,2 @@ | ||
# rscx 🪶 | ||
|
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 @@ | ||
# testing subfolders :) |
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,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! { | ||
<Shell> | ||
<Mdx source=md handler=handler /> | ||
</Shell> | ||
} | ||
} | ||
|
||
async fn handler(name: String, _props: MdxComponentProps) -> String { | ||
match name { | ||
_ => html! {}, | ||
} | ||
} | ||
|
||
#[component] | ||
async fn Shell(children: String) -> String { | ||
html! { | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>rscx</title> | ||
<link rel="stylesheet" href="/bundle.css" /> | ||
</head> | ||
<body class=csm!{Body, | ||
max-width: 600px, | ||
margin: auto, | ||
}> | ||
{children} | ||
</body> | ||
</html> | ||
} | ||
} |