1
Fork 0

Compare commits

...

6 Commits

Author SHA1 Message Date
Bauke 8d9cfa8ad0
Add trash-cli. 2024-01-15 16:32:43 +01:00
Bauke 2352cb5a61
Update dependencies. 2024-01-15 16:31:42 +01:00
Bauke 0a646f0763
Add missing docs lints and add documentation. 2024-01-15 15:55:29 +01:00
Bauke 9b434f8cfe
Remove obsolete redirects. 2024-01-15 15:46:14 +01:00
Bauke aa37acf1dc
Move the pnpm scripts to cargo-make tasks. 2024-01-15 15:45:17 +01:00
Bauke 1549473c46
Add Nix flake and direnv files. 2024-01-15 13:15:26 +01:00
17 changed files with 179 additions and 78 deletions

3
.envrc Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
use flake

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.direnv/
.netlify/
node_modules/
public/

View File

@ -14,10 +14,10 @@ name = "bauke-xyz"
path = "source/main.rs"
[dependencies]
askama = "0.11.1"
askama = "0.12.1"
color-eyre = "0.6.2"
comrak = "0.15.0"
minify-html = "0.10.7"
comrak = "0.20.0"
minify-html = "0.15.0"
rsass = "0.23.4"
toml-frontmatter = "0.1.0"
@ -28,3 +28,10 @@ version = "1.0.152"
[dependencies.userstyles]
git = "https://git.bauke.xyz/Bauke/userstyles"
rev = "8aa9ad3"
[lints.clippy]
missing_docs_in_private_items = "warn"
[lints.rust]
missing_docs = "warn"
unsafe_code = "forbid"

View File

@ -1,40 +1,41 @@
[tasks.fmt]
command = "cargo"
args = ["fmt", "${@}"]
[tasks.check]
command = "cargo"
args = ["check", "${@}"]
[tasks.clippy]
command = "cargo"
args = ["clippy", "${@}"]
[tasks.test]
command = "cargo"
args = ["test", "${@}"]
[tasks.doc]
command = "cargo"
args = ["doc", "${@}"]
# Build the website.
[tasks.build]
clear = true
command = "cargo"
args = ["build", "${@}"]
args = ["run", "--release"]
[tasks.complete-check]
dependencies = ["fmt", "check", "clippy", "test", "doc", "build"]
# Remove build directories.
[tasks.clean]
clear = true
command = "pnpm"
args = ["trash", "public"]
[tasks.code-coverage]
workspace = false
install_crate = "cargo-tarpaulin"
# Deploy the website to Netlify.
[tasks.deploy-netlify]
clear = true
command = "pnpm"
dependencies = ["clean", "lint", "build"]
args = ["netlify", "deploy", "-p", "-d", "public/", "-s", "bauke.xyz"]
# Run all other linting tasks.
[tasks.lint]
clear = true
dependencies = ["lint-clippy", "lint-js", "lint-scss"]
# Run Clippy.
[tasks.lint-clippy]
clear = true
command = "cargo"
args = [
"tarpaulin",
"--exclude-files=target/*",
"--out=html",
"--output-dir=coverage",
"--skip-clean",
"--target-dir=target/tarpaulin",
"--workspace"
]
args = ["clippy"]
# Run XO.
[tasks.lint-js]
clear = true
command = "pnpm"
args = ["xo"]
# Run Stylelint.
[tasks.lint-scss]
clear = true
command = "pnpm"
args = ["stylelint", "source/**/*.scss"]

View File

@ -4,12 +4,7 @@
## Development
Requires working installations of [Rust and Cargo](https://www.rust-lang.org/learn/get-started), [NodeJS](https://nodejs.org) and [pnpm](https://pnpm.io).
* Install the dependencies with `pnpm install`.
* Build the website with `cargo run`.
* Deploy to Netlify with `pnpm run deploy`.
* Test the code with `pnpm test`.
With [Nix flakes](https://nixos.wiki/wiki/Flakes) and [direnv](https://direnv.net/) installed and enabled, all the required dependencies are automatically loaded from [`shell.nix`](./shell.nix). Then [cargo-make](https://sagiegurari.github.io/cargo-make/) can be used to build, deploy and lint the code. The available tasks are all described in the [`Makefile.toml`](Makefile.toml) configuration.
## License

59
flake.lock Normal file
View File

@ -0,0 +1,59 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1705242415,
"narHash": "sha256-a8DRYrNrzTudvO7XHUPNJD89Wbf1ZZT0VbwCsPnHWaE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ea780f3de2d169f982564128804841500e85e373",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

13
flake.nix Normal file
View File

@ -0,0 +1,13 @@
{
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = import ./shell.nix { inherit pkgs; };
}
);
}

View File

@ -1,20 +1,16 @@
{
"private": "true",
"scripts": {
"deploy": "cargo run --release -q && pnpm deploy:netlify",
"deploy:netlify": "netlify deploy --prod --dir 'public/' -s bauke.xyz",
"test": "xo && stylelint 'source/**/*.scss'"
},
"dependencies": {
"modern-normalize": "^1.1.0"
"modern-normalize": "^2.0.0"
},
"devDependencies": {
"@bauke/eslint-config": "^0.1.2",
"@bauke/prettier-config": "^0.1.2",
"@bauke/stylelint-config": "^0.1.2",
"netlify-cli": "^12.5.0",
"stylelint": "^14.16.1",
"xo": "^0.53.1"
"@bauke/eslint-config": "^0.1.5",
"@bauke/prettier-config": "^0.1.5",
"@bauke/stylelint-config": "^0.1.5",
"netlify-cli": "^17.13.2",
"stylelint": "^16.1.0",
"trash-cli": "^5.0.0",
"xo": "^0.56.0"
},
"prettier": "@bauke/prettier-config",
"stylelint": {

7
shell.nix Normal file
View File

@ -0,0 +1,7 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
mkShell rec {
packages = [ cargo-make nodejs nodePackages.pnpm ];
}

View File

@ -1,10 +1,14 @@
//! The logic for files that need be directly copied over.
use std::{fs, path::Path, process::Command};
use color_eyre::Result;
/// Struct to contain functionality for copying.
pub struct Copy;
impl Copy {
/// Copy all the files to their respective destinations.
pub fn write(
build_dir: &Path,
public_dir: &Path,

View File

@ -1,3 +1,7 @@
//! # Bauke 🦖 XYZ
//!
//! > **Bauke's website.**
use std::{
fs,
path::{Path, PathBuf},
@ -27,6 +31,7 @@ fn main() -> Result<()> {
Ok(())
}
/// Write the userstyle files to the right place in the build directory.
fn build_userstyles(build_dir: &Path) -> Result<()> {
for target in userstyles::ALL_USERSTYLES {
let style = userstyles::Userstyle::load(target)?;

View File

@ -1,8 +1,8 @@
//! Code for minifying.
use color_eyre::Result;
/**
Minify HTML using [`minify-html`].
*/
/// Minify HTML using [`minify-html`].
pub fn html(data: String) -> Result<String> {
let minify_config = minify_html::Cfg {
do_not_minify_doctype: true,
@ -10,9 +10,13 @@ pub fn html(data: String) -> Result<String> {
keep_closing_tags: true,
keep_comments: false,
keep_html_and_head_opening_tags: true,
keep_input_type_text_attr: true,
keep_spaces_between_attributes: true,
keep_ssi_comments: false,
minify_css: false,
minify_js: false,
preserve_brace_template_syntax: false,
preserve_chevron_percent_template_syntax: false,
remove_bangs: false,
remove_processing_instructions: false,
};

View File

@ -4,11 +4,7 @@
# Other redirects
/driftingnebula https://driftingnebula.com
/git https://git.bauke.xyz
/gitea https://git.bauke.xyz
/github https://github.com/Bauke
/gitlab https://gitlab.com/Bauke
/glimesh https://glimesh.tv/Bauke
/holllo https://holllo.org
/tildes https://tildes.net/user/Bauke
/twitch https://twitch.tv/Bauke
/youtube https://www.youtube.com/@baukexyz

View File

@ -1,3 +1,5 @@
//! Logic for building and writing the SCSS.
use std::{
fs::{create_dir_all, write},
path::Path,
@ -9,9 +11,11 @@ use rsass::{
output::{Format, Style},
};
/// Struct to contain functionality for building the SCSS.
pub struct Scss;
impl Scss {
/// Build the SCSS and write the CSS to their respective places.
pub fn write(public_dir: &Path, source_dir: &Path) -> Result<()> {
let css_dir = public_dir.join("css");
create_dir_all(&css_dir)?;

View File

@ -1,3 +1,5 @@
//! The main [`askama`] templates.
use std::{
fs::{create_dir_all, write},
path::Path,
@ -6,13 +8,16 @@ use std::{
use askama::Template;
use color_eyre::Result;
/// The template for the home page.
#[derive(Debug, Template)]
#[template(path = "index.html")]
pub struct Index {
/// The text for the `<title>` element.
pub page_title: String,
}
impl Index {
/// Build, minify and write the template.
pub fn write(public_dir: &Path) -> Result<()> {
let destination = public_dir.join("index.html");
create_dir_all(destination.parent().unwrap())?;

View File

@ -1,10 +1,6 @@
/*!
Filters for Askama templates.
*/
//! Custom filters for [`askama`] templates.
/**
Get the DRG mod link and title from a given ID.
*/
/// Get the DRG mod link and title from a given ID.
pub fn drg_mod(mod_id: &str) -> askama::Result<(String, &str)> {
let mods = std::collections::HashMap::<_, _>::from_iter([
("brighter-objects", "Brighter Objects"),
@ -16,15 +12,13 @@ pub fn drg_mod(mod_id: &str) -> askama::Result<(String, &str)> {
Ok((format!("https://drg.mod.io/{mod_id}"), mod_title))
}
/**
Turn a timestamp with format `mm:ss` into its total seconds.
## Examples
- `00:30` -> 30 seconds
- `01:00` -> 60 seconds
- `01:30` -> 90 seconds
*/
/// Turn a timestamp with format `mm:ss` into its total seconds.
///
/// ## Examples
///
/// - `00:30` -> 30 seconds
/// - `01:00` -> 60 seconds
/// - `01:30` -> 90 seconds
pub fn timestamp_to_seconds(timestamp: &str) -> askama::Result<i32> {
let mut split = timestamp.split(':');
let minutes = split.next().map(str::parse::<i32>).unwrap().unwrap();

View File

@ -1,3 +1,5 @@
//! Templates, data structures and logic for the video pages.
use std::{fs, path::Path};
use {
@ -8,6 +10,7 @@ use {
mod filters;
/// The template for videos.
#[derive(Debug, Template)]
#[template(path = "video.html")]
pub struct VideoTemplate {
@ -27,6 +30,7 @@ pub struct VideoTemplate {
pub video_id: String,
}
/// The frontmatter data for a video.
#[derive(Debug, Deserialize)]
pub struct VideoData {
/// Deep Rock Galactic data.
@ -46,6 +50,7 @@ pub struct VideoData {
pub tags: Vec<String>,
}
/// Data for speedrun videos.
#[derive(Debug, Deserialize)]
pub struct SpeedrunData {
/// Video chapters as with timestamps and chapter titles.
@ -61,12 +66,14 @@ pub struct SpeedrunData {
pub mods: Option<Vec<String>>,
}
/// Additional data for Deep Rock Galactic videos.
#[derive(Debug, Deserialize)]
pub struct DeepRockGalacticData {
/// Deep Rock Galactic mods used in the run.
pub mods: Option<Vec<String>>,
}
/// Compile and write all the found videos to their respective locations.
pub fn write_all(public_dir: &Path) -> Result<()> {
let video_datas = {
let mut data = vec![];