Improve OG descriptions and fix Nix builds
This commit is contained in:
parent
25bc697309
commit
b0acb2fc9a
6 changed files with 87 additions and 45 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -3026,7 +3026,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "samey"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"async-trait",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "samey"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
license = "MIT"
|
||||
|
|
|
|||
103
default.nix
103
default.nix
|
|
@ -3,16 +3,24 @@ let
|
|||
nixpkgs
|
||||
rust-overlay
|
||||
;
|
||||
pkgs = import nixpkgs {
|
||||
currentPkgs = import nixpkgs {
|
||||
overlays = [ (import rust-overlay) ];
|
||||
};
|
||||
inherit (pkgs) lib stdenv;
|
||||
inherit (currentPkgs) lib stdenv;
|
||||
|
||||
# Options for your package
|
||||
pname = "samey";
|
||||
version = "0.1.0";
|
||||
docker-image = "badmanners/samey";
|
||||
crate-info = fromTOML (builtins.readFile ./Cargo.toml);
|
||||
pname = crate-info.package.name;
|
||||
version = crate-info.package.version;
|
||||
|
||||
docker-image = "badmanners/${pname}";
|
||||
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 {
|
||||
root = ./.;
|
||||
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 = [
|
||||
"x86_64-unknown-linux-gnu"
|
||||
"aarch64-unknown-linux-gnu"
|
||||
|
|
@ -34,7 +61,7 @@ let
|
|||
};
|
||||
|
||||
mkRustPkg =
|
||||
target:
|
||||
targetTriple:
|
||||
stdenv.mkDerivation {
|
||||
inherit
|
||||
pname
|
||||
|
|
@ -42,70 +69,64 @@ let
|
|||
src
|
||||
;
|
||||
|
||||
cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
|
||||
inherit src;
|
||||
cargoDeps = currentPkgs.rustPlatform.fetchCargoVendor {
|
||||
src = cargo-src;
|
||||
hash = cargo-deps-hash;
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkgs.rustPlatform.cargoSetupHook
|
||||
pkgs.zig
|
||||
currentPkgs.rustPlatform.cargoSetupHook
|
||||
currentPkgs.zig
|
||||
rust-bin
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
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 = ''
|
||||
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 =
|
||||
targetAttrs:
|
||||
{
|
||||
system,
|
||||
pkgs,
|
||||
tag,
|
||||
targetTriple,
|
||||
}:
|
||||
let
|
||||
pkgs-cross =
|
||||
if targetAttrs.system == builtins.currentSystem then
|
||||
pkgs
|
||||
if system == builtins.currentSystem then
|
||||
currentPkgs
|
||||
else
|
||||
(import nixpkgs {
|
||||
crossSystem = targetAttrs.system;
|
||||
crossSystem = system;
|
||||
});
|
||||
rust-package = mkRustPkg targetAttrs.target;
|
||||
rust-package = mkRustPkg targetTriple;
|
||||
in
|
||||
pkgs-cross.dockerTools.buildLayeredImage {
|
||||
name = docker-image;
|
||||
inherit (targetAttrs) tag;
|
||||
inherit tag;
|
||||
contents = [
|
||||
targetAttrs.pkgs.ffmpeg-headless
|
||||
pkgs.ffmpeg-headless
|
||||
pkgs.glibc
|
||||
];
|
||||
config.Entrypoint = [
|
||||
"${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
|
||||
{
|
||||
docker-amd64 = mkDocker amd64;
|
||||
docker-arm64 = mkDocker arm64;
|
||||
samey = mkRustPkg currentTargetTriple;
|
||||
docker-amd64 = mkDocker archs.amd64;
|
||||
docker-arm64 = mkDocker archs.arm64;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
services:
|
||||
samey:
|
||||
image: badmanners/samey:latest
|
||||
image: badmanners/samey:latest-amd64
|
||||
build:
|
||||
context: .
|
||||
container_name: samey
|
||||
|
|
|
|||
21
src/views.rs
21
src/views.rs
|
|
@ -1460,6 +1460,7 @@ struct ViewPostPageTemplate {
|
|||
application_name: String,
|
||||
age_confirmation: bool,
|
||||
post: samey_post::Model,
|
||||
description_plaintext: Option<String>,
|
||||
pool_data: Vec<PostPoolData>,
|
||||
tags: Vec<samey_tag::Model>,
|
||||
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 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(
|
||||
ViewPostPageTemplate {
|
||||
application_name,
|
||||
age_confirmation,
|
||||
post,
|
||||
description_plaintext,
|
||||
pool_data,
|
||||
tags,
|
||||
tags_text: query.tags,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
{% 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 %}
|
||||
<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" %}
|
||||
<meta property="og:image" content="/files/{{ post.media }}" />
|
||||
<meta property="og:image:width" content="{{ post.width }}" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue