Compare commits

...

3 Commits

Author SHA1 Message Date
a45f1b3b99 Deploy extra small 2025-10-29 19:32:44 +08:00
2fd346d477 Add additional build configurations 2025-10-29 19:31:50 +08:00
a88222184f Update git output section 2025-10-29 19:31:01 +08:00
6 changed files with 46 additions and 4 deletions

9
.cargo/config.toml Normal file
View File

@@ -0,0 +1,9 @@
[profile.small]
inherits = "release"
opt-level = "z"
codegen-units = 1
lto = true
[profile.extra-small]
inherits = "small"
panic = "abort"

Binary file not shown.

View File

@@ -37,13 +37,14 @@ function WriteWorkspace()
end end
-- Write the workspace file -- Write the workspace file
w("return "); wv(Lemon.workspace); nl() w("return "); wv(Lemon.ws); nl()
vim.fn.writefile(s.ls, Lemon.ws_file) vim.fn.writefile(s.ls, Lemon.ws_file)
end end
-- Loads the workspace from the file, or return the default -- Loads the workspace from the file, or return the default
---@param default table ---@param default table
---@return table ---@return table
function InitWorkspace(default) function InitWorkspace(default)
Lemon.ws = LoadWorkspace() Lemon.ws = LoadWorkspace()
if Lemon.ws == nil then if Lemon.ws == nil then

View File

@@ -17,6 +17,33 @@ I wanted to have a setup that generates static html from something like markdown
I decided to do something similar, however I used rust as it has some popular existing libraries for web servers and parsing markdown. The reason for writing an application to host the blog is that I wanted to have it automatically respond to a git webhook which would automatically pull the latest git repo and then rebuild the articles from their markdown files. I decided to do something similar, however I used rust as it has some popular existing libraries for web servers and parsing markdown. The reason for writing an application to host the blog is that I wanted to have it automatically respond to a git webhook which would automatically pull the latest git repo and then rebuild the articles from their markdown files.
## Parsing the git output
As mentioned in [this article](https://gaultier.github.io/blog/making_my_static_blog_generator_11_times_faster.html) they use the git log command to retrieve the blog files, which I decided to also use. I found out there is a way to retreive the output from git in the following predictable format:
```
c584d39 - 1761735775 - Update server post and fix post titles
:100644 100644 d5e614a 678eb09 M posts/blog-server.md
9d5f86a - 1761415068 - Template
:000000 100644 0000000 d5e614a A posts/blog-server.md
```
Retrieved with the following command line: `git log --raw --no-merges --pretty="%h - %ad - %s" --date=unix -- posts`
Where the first entry will always be a commit hash followed by unix time stamp and then the commit name. After that it will list files affected by this commit, prefixed with a colon (:).
Then we can simply parse this by reading line by line and attributing the following file changes to the commit that was above it. Then I use the first encounter of a given file to determine the creation date, and the last encounter to determine the update date.
### (Bonus) Parsing the git version
There's a nice trick to retrieve the current git branch and commit hash by just reading 2 files, which I grabbed from one of my CMake scripts that uses it to inject the git version into my code on every compile. It's super fast since it doesn't actually run any git commands to retrieve this information.
The process is, read .git/HEAD, which will either contain just the hash, or something like `ref: refs/heads/main`.\
In the later case, you can just read from .git/refs/heads/main which will then contain your git hash.
This version is inserted at the bottom of the page so I can tell which version it's at.
## HTML ## HTML
Of course there is also some styling and markup required for the shell, like the navigation bar and footers.\ Of course there is also some styling and markup required for the shell, like the navigation bar and footers.\

View File

@@ -5,5 +5,5 @@ pushd $ROOT
set -ex set -ex
cargo build --release cargo build --profile extra-small
cp -f target/release/blog-server ./ cp -f target/extra-small/blog-server ./

View File

@@ -12,7 +12,7 @@ use axum::{
use clap::Parser; use clap::Parser;
use std::sync::Arc; use std::sync::Arc;
use tokio::process::Command; use tokio::process::Command;
use tokio::sync::RwLock; use tokio::sync::{Mutex, RwLock};
use tower_http::services::ServeDir; use tower_http::services::ServeDir;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@@ -26,6 +26,7 @@ struct Args {
#[derive(Clone)] #[derive(Clone)]
struct AppState { struct AppState {
post_manager: Arc<RwLock<post_manager::PostManager>>, post_manager: Arc<RwLock<post_manager::PostManager>>,
update_lock: Arc<Mutex<()>>,
} }
#[tokio::main] #[tokio::main]
@@ -38,6 +39,7 @@ async fn main() {
let app_state = AppState { let app_state = AppState {
post_manager: post_manager.clone(), post_manager: post_manager.clone(),
update_lock: Arc::new(Mutex::new(())),
}; };
if args.no_cache { if args.no_cache {
@@ -105,6 +107,9 @@ async fn post_handler(
} }
async fn update_handler(State(state): State<AppState>) -> impl IntoResponse { async fn update_handler(State(state): State<AppState>) -> impl IntoResponse {
// Acquire lock to prevent concurrent updates
let _lock = state.update_lock.lock().await;
// Run git pull --autostash // Run git pull --autostash
let output = Command::new("git") let output = Command::new("git")
.arg("pull") .arg("pull")