Improve OG descriptions and fix Nix builds

This commit is contained in:
Bad Manners 2026-01-17 15:53:33 -03:00
parent 25bc697309
commit b0acb2fc9a
6 changed files with 87 additions and 45 deletions

2
Cargo.lock generated
View file

@ -3026,7 +3026,7 @@ dependencies = [
[[package]] [[package]]
name = "samey" name = "samey"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"askama", "askama",
"async-trait", "async-trait",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "samey" name = "samey"
version = "0.1.0" version = "0.1.1"
edition = "2024" edition = "2024"
rust-version = "1.85" rust-version = "1.85"
license = "MIT" license = "MIT"

View file

@ -3,16 +3,24 @@ let
nixpkgs nixpkgs
rust-overlay rust-overlay
; ;
pkgs = import nixpkgs { currentPkgs = import nixpkgs {
overlays = [ (import rust-overlay) ]; overlays = [ (import rust-overlay) ];
}; };
inherit (pkgs) lib stdenv; inherit (currentPkgs) lib stdenv;
# Options for your package crate-info = fromTOML (builtins.readFile ./Cargo.toml);
pname = "samey"; pname = crate-info.package.name;
version = "0.1.0"; version = crate-info.package.version;
docker-image = "badmanners/samey";
docker-image = "badmanners/${pname}";
cargo-deps-hash = "sha256-oiz2a6Vip199saU/s/sBn/3Cl0eJaSltN3n1uPETHGk="; cargo-deps-hash = "sha256-oiz2a6Vip199saU/s/sBn/3Cl0eJaSltN3n1uPETHGk=";
cargo-src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
];
};
src = lib.fileset.toSource { src = lib.fileset.toSource {
root = ./.; root = ./.;
fileset = lib.fileset.unions [ fileset = lib.fileset.unions [
@ -26,7 +34,26 @@ let
]; ];
}; };
rust-bin = pkgs.rust-bin.stable.latest.default.override { archs = {
amd64 = {
system = "x86_64-linux";
pkgs = import nixpkgs {
localSystem = "x86_64-linux";
};
tag = "latest-amd64";
targetTriple = "x86_64-unknown-linux-gnu";
};
arm64 = {
system = "aarch64-linux";
pkgs = import nixpkgs {
localSystem = "aarch64-linux";
};
tag = "latest-arm64";
targetTriple = "aarch64-unknown-linux-gnu";
};
};
rust-bin = currentPkgs.rust-bin.stable.latest.default.override {
targets = [ targets = [
"x86_64-unknown-linux-gnu" "x86_64-unknown-linux-gnu"
"aarch64-unknown-linux-gnu" "aarch64-unknown-linux-gnu"
@ -34,7 +61,7 @@ let
}; };
mkRustPkg = mkRustPkg =
target: targetTriple:
stdenv.mkDerivation { stdenv.mkDerivation {
inherit inherit
pname pname
@ -42,70 +69,64 @@ let
src src
; ;
cargoDeps = pkgs.rustPlatform.fetchCargoVendor { cargoDeps = currentPkgs.rustPlatform.fetchCargoVendor {
inherit src; src = cargo-src;
hash = cargo-deps-hash; hash = cargo-deps-hash;
}; };
nativeBuildInputs = [ nativeBuildInputs = [
pkgs.rustPlatform.cargoSetupHook currentPkgs.rustPlatform.cargoSetupHook
pkgs.zig currentPkgs.zig
rust-bin rust-bin
]; ];
buildPhase = '' buildPhase = ''
export HOME=$(mktemp -d) export HOME=$(mktemp -d)
${pkgs.cargo-zigbuild}/bin/cargo-zigbuild zigbuild --release --target ${target} ${currentPkgs.cargo-zigbuild}/bin/cargo-zigbuild zigbuild --release --target ${targetTriple}
''; '';
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
cp ./target/${target}/release/${pname} $out/bin/ cp ./target/${targetTriple}/release/${pname} $out/bin/
''; '';
}; };
amd64 = {
system = "x86_64-linux";
pkgs = import nixpkgs {
localSystem = "x86_64-linux";
};
tag = "latest-amd64";
target = "x86_64-unknown-linux-gnu";
};
arm64 = {
system = "aarch64-linux";
pkgs = import nixpkgs {
localSystem = "aarch64-linux";
};
tag = "latest-arm64";
target = "aarch64-unknown-linux-gnu";
};
mkDocker = mkDocker =
targetAttrs: {
system,
pkgs,
tag,
targetTriple,
}:
let let
pkgs-cross = pkgs-cross =
if targetAttrs.system == builtins.currentSystem then if system == builtins.currentSystem then
pkgs currentPkgs
else else
(import nixpkgs { (import nixpkgs {
crossSystem = targetAttrs.system; crossSystem = system;
}); });
rust-package = mkRustPkg targetAttrs.target; rust-package = mkRustPkg targetTriple;
in in
pkgs-cross.dockerTools.buildLayeredImage { pkgs-cross.dockerTools.buildLayeredImage {
name = docker-image; name = docker-image;
inherit (targetAttrs) tag; inherit tag;
contents = [ contents = [
targetAttrs.pkgs.ffmpeg-headless pkgs.ffmpeg-headless
pkgs.glibc
]; ];
config.Entrypoint = [ config.Entrypoint = [
"${rust-package}/bin/${pname}" "${rust-package}/bin/${pname}"
]; ];
}; };
currentTargetTriple =
(lib.lists.findFirst (arch: arch.system == builtins.currentSystem) {
targetTriple = throw "Unknown current system ${builtins.currentSystem}";
} (lib.attrValues archs)).targetTriple;
in in
{ {
docker-amd64 = mkDocker amd64; samey = mkRustPkg currentTargetTriple;
docker-arm64 = mkDocker arm64; docker-amd64 = mkDocker archs.amd64;
docker-arm64 = mkDocker archs.arm64;
} }

View file

@ -1,6 +1,6 @@
services: services:
samey: samey:
image: badmanners/samey:latest image: badmanners/samey:latest-amd64
build: build:
context: . context: .
container_name: samey container_name: samey

View file

@ -1460,6 +1460,7 @@ struct ViewPostPageTemplate {
application_name: String, application_name: String,
age_confirmation: bool, age_confirmation: bool,
post: samey_post::Model, post: samey_post::Model,
description_plaintext: Option<String>,
pool_data: Vec<PostPoolData>, pool_data: Vec<PostPoolData>,
tags: Vec<samey_tag::Model>, tags: Vec<samey_tag::Model>,
tags_text: Option<String>, tags_text: Option<String>,
@ -1563,11 +1564,31 @@ pub(crate) async fn view_post_page(
let pool_data = get_pool_data_for_post(&db, post_id, auth_session.user.as_ref()).await?; let pool_data = get_pool_data_for_post(&db, post_id, auth_session.user.as_ref()).await?;
let description_plaintext = post.description.as_ref().map(|description| {
use pulldown_cmark::{Event, Options, Parser, TagEnd, html::write_html_fmt};
let parser = Parser::new_ext(description, Options::empty())
.map(|event| match event {
Event::End(TagEnd::Paragraph) => Event::Text(" ".into()),
_ => event,
})
.filter(|event| match event {
Event::Text(_) => true,
_ => false,
});
let mut buf = String::new();
write_html_fmt(&mut buf, parser)
.ok()
.map(|_| buf)
.unwrap_or_else(|| description.clone())
});
Ok(Html( Ok(Html(
ViewPostPageTemplate { ViewPostPageTemplate {
application_name, application_name,
age_confirmation, age_confirmation,
post, post,
description_plaintext,
pool_data, pool_data,
tags, tags,
tags_text: query.tags, tags_text: query.tags,

View file

@ -6,7 +6,7 @@
{% include "fragments/common_headers.html" %} {% include "fragments/common_headers.html" %}
{% if let Some(title) = post.title %}<meta property="og:title" content="{{ title }}"/>{% else %}<meta property="og:title" content="{{ tags_post }}" />{% endif %} {% if let Some(title) = post.title %}<meta property="og:title" content="{{ title }}"/>{% else %}<meta property="og:title" content="{{ tags_post }}" />{% endif %}
<meta property="og:url" content="/post/{{ post.id }}" /> <meta property="og:url" content="/post/{{ post.id }}" />
{% if let Some(description) = post.description %}<meta property="og:description" content="{{ description | markdown | escape }}" />{% endif %} {% if let Some(description) = description_plaintext %}<meta property="og:description" content="{{ description }}" />{% endif %}
{% match post.media_type.as_ref() %} {% when "image" %} {% match post.media_type.as_ref() %} {% when "image" %}
<meta property="og:image" content="/files/{{ post.media }}" /> <meta property="og:image" content="/files/{{ post.media }}" />
<meta property="og:image:width" content="{{ post.width }}" /> <meta property="og:image:width" content="{{ post.width }}" />