Improve OG descriptions and fix Nix builds
This commit is contained in:
parent
25bc697309
commit
15486c36ca
6 changed files with 113 additions and 48 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -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",
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
108
default.nix
108
default.nix
|
|
@ -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";
|
|
||||||
cargo-deps-hash = "sha256-oiz2a6Vip199saU/s/sBn/3Cl0eJaSltN3n1uPETHGk=";
|
docker-image = "badmanners/${pname}";
|
||||||
|
cargo-deps-hash = "sha256-PD/ZR/sdmqA18xcOi9AnwQtDYVyELPS6GBF/pzcJzkE=";
|
||||||
|
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,15 +34,34 @@ 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-musl";
|
||||||
|
};
|
||||||
|
arm64 = {
|
||||||
|
system = "aarch64-linux";
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
localSystem = "aarch64-linux";
|
||||||
|
};
|
||||||
|
tag = "latest-arm64";
|
||||||
|
targetTriple = "aarch64-unknown-linux-musl";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
rust-bin = currentPkgs.rust-bin.stable.latest.default.override {
|
||||||
targets = [
|
targets = [
|
||||||
"x86_64-unknown-linux-gnu"
|
"x86_64-unknown-linux-musl"
|
||||||
"aarch64-unknown-linux-gnu"
|
"aarch64-unknown-linux-musl"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
mkRustPkg =
|
mkRustPkg =
|
||||||
target:
|
targetTriple:
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
inherit
|
inherit
|
||||||
pname
|
pname
|
||||||
|
|
@ -42,70 +69,63 @@ 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
|
||||||
];
|
];
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
src/main.rs
24
src/main.rs
|
|
@ -84,7 +84,31 @@ async fn main() {
|
||||||
} else {
|
} else {
|
||||||
println!("Listening on http://{}:{}", address, port);
|
println!("Listening on http://{}:{}", address, port);
|
||||||
}
|
}
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
let mut signal_terminate =
|
||||||
|
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
|
||||||
|
.unwrap();
|
||||||
|
let mut signal_interrupt =
|
||||||
|
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::interrupt())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
tokio::select! {
|
||||||
|
server = axum::serve(listener, app) => {
|
||||||
|
server.unwrap();
|
||||||
|
},
|
||||||
|
_ = signal_terminate.recv() => {
|
||||||
|
println!("Received SIGTERM");
|
||||||
|
},
|
||||||
|
_ = signal_interrupt.recv() => {
|
||||||
|
println!("Received SIGINT");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
{
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
src/views.rs
21
src/views.rs
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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 }}" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue