nix package, better errors

This commit is contained in:
Rakarake 2026-04-05 22:07:32 +02:00
parent 36c3967170
commit f398e4336d
2 changed files with 13 additions and 4 deletions

View file

@ -1,5 +1,5 @@
{ {
description = "Rust flake"; description = "mdf-blog";
inputs = inputs =
{ {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # or whatever vers nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # or whatever vers
@ -16,6 +16,14 @@
}; };
in in
{ {
defaultPackage = pkgs.rustPlatform.buildRustPackage {
name = "mdf-blog";
pname = "mdf-blog";
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
};
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
packages = with pkgs; [ packages = with pkgs; [
rustc rustc

View file

@ -2,9 +2,10 @@ use std::{collections::HashMap, io, path::Path};
use markdown::to_html; use markdown::to_html;
use rss::{Channel, ChannelBuilder, GuidBuilder, Item, ItemBuilder}; use rss::{Channel, ChannelBuilder, GuidBuilder, Item, ItemBuilder};
fn main() -> io::Result<()> { fn main() -> Result<(), String> {
let posts = std::env::args().skip(2).map(|f| { let posts = std::env::args().skip(2).map(|f| {
let contents = std::fs::read_to_string(f.clone())?; let contents = std::fs::read_to_string(f.clone()).map_err(|e| format!("when reading file {f} got {e}"))?;
// parse metadata, then the rest to html // parse metadata, then the rest to html
let mut metadata: HashMap<String, String> = contents.lines().take_while(|l| { let mut metadata: HashMap<String, String> = contents.lines().take_while(|l| {
// header ends here // header ends here
@ -26,7 +27,7 @@ fn main() -> io::Result<()> {
}).concat(); }).concat();
Ok((to_html(&body), metadata)) Ok((to_html(&body), metadata))
}).collect::<Result<Vec<(String, HashMap<String, String>)>, io::Error>>()?; }).collect::<Result<Vec<(String, HashMap<String, String>)>, String>>()?;
if let Some(mode) = std::env::args().skip(1).next() { if let Some(mode) = std::env::args().skip(1).next() {
match mode.as_str() { match mode.as_str() {