Add zola #5

Merged
kjuulh merged 3 commits from feat/zola into main 2023-04-03 02:49:42 +02:00
12 changed files with 2399 additions and 10 deletions
Showing only changes of commit c4cb0c6d81 - Show all commits

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
public/
node_modules/
.env
target/

2164
ci/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

15
ci/Cargo.toml Normal file
View File

@ -0,0 +1,15 @@
[package]
name = "ci"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = "0.4.24"
color-eyre = "0.6.2"
dagger-sdk = "0.2.19"
eyre = "0.6.8"
tokio = { version = "1.27.0", features = ["full"] }
tokio-scoped = "0.2.0"
dotenv = "0.15.0"

148
ci/src/main.rs Normal file
View File

@ -0,0 +1,148 @@
use std::sync::Arc;
use dagger_sdk::{HostDirectoryOptsBuilder, QueryContainerOptsBuilder};
use tokio::sync::Mutex;
#[tokio::main]
async fn main() -> eyre::Result<()> {
dotenv::dotenv().unwrap();
let client = dagger_sdk::connect().await?;
let src = client.host().directory_opts(
".",
HostDirectoryOptsBuilder::default()
.exclude(vec![".git", "node_modules", "public", "ci", "target"])
.build()?,
);
let node_cache = client.cache_volume("node_cache");
let debian_cache = client.cache_volume("debian_cache");
let styles_file = client
.container()
.from("node:16")
.with_workdir("/app")
.with_directory(".", src.id().await?)
.with_mounted_cache("node_modules", node_cache.id().await?)
.with_exec(vec!["yarn"])
.with_exec(vec!["yarn", "compile"])
.file("static/styles/styles.css");
let zola_version = "0.17.2-1";
let debian_edition = "bullseye";
let debian_platform = "amd64";
let tag = chrono::Utc::now().timestamp();
let github_zola_download = format!("https://github.com/barnumbirr/zola-debian/releases/download/v{zola_version}/zola_{zola_version}_{debian_platform}_{debian_edition}.deb");
let pull_articles = client
.container()
.from("docker.io/kasperhermansen/pull-articles:1680482220")
.with_exec(vec!["echo", &format!("{}", tag)])
.with_env_variable("GIT_USERNAME", "kjuulh")
.with_env_variable("GIT_PASSWORD", std::env::var("GIT_PASSWORD").unwrap())
.with_exec(vec![
"pull-articles",
"--repo",
"https://git.front.kjuulh.io/kjuulh/obsidian.git",
"--path",
"areas/blog/posts",
"--out",
"/mnt/posts",
])
.directory("/mnt/posts");
let dist_dir = client
.container_opts(
dagger_sdk::QueryContainerOptsBuilder::default()
.platform(format!("linux/{debian_platform}"))
.build()?,
)
.from(format!("debian:{debian_edition}"))
.with_exec(vec!["apt", "update"])
.with_exec(vec!["apt", "install", "wget", "-y"])
.with_workdir("/mnt")
.with_mounted_cache("/mnt", debian_cache.id().await?)
.with_exec(vec!["wget", &github_zola_download])
.with_exec(vec![
"dpkg",
"-i",
format!("zola_{zola_version}_{debian_platform}_{debian_edition}.deb").as_str(),
])
.with_workdir("/app")
.with_directory(".", src.id().await?)
.with_directory("content/posts", pull_articles.id().await?)
.with_file(
"content/posts/_index.md",
src.file("content/posts/_index.md").id().await?,
)
.with_file("static/styles/styles.css", styles_file.id().await?)
.with_exec(vec!["zola", "build"])
.directory("public");
let caddy_file = client.host().directory("deployment").file("Caddyfile");
let variants = vec!["linux/amd64", "linux/arm64"];
let platform_variants = Arc::new(Mutex::new(Vec::new()));
tokio_scoped::scope(|s| {
for platform in variants {
let caddy_file = caddy_file.clone();
let client = client.clone();
let dist_dir = dist_dir.clone();
let platform_variants = platform_variants.clone();
s.spawn(async move {
let dep_image = client
.container_opts(
QueryContainerOptsBuilder::default()
.platform(platform)
.build()
.unwrap(),
)
.from("caddy")
.with_directory("/usr/share/caddy", dist_dir.id().await.unwrap())
.with_file("/etc/caddy/Caddyfile", caddy_file.id().await.unwrap());
let mut platform_variants = platform_variants.lock().await;
platform_variants.push(dep_image.id().await.unwrap())
});
}
});
let variants = platform_variants
.lock()
.await
.iter()
.map(|c| c.clone())
.collect::<Vec<_>>();
let version = client
.container()
.publish_opts(
format!("kasperhermansen/kasperhermansen-blog:{tag}"),
dagger_sdk::ContainerPublishOptsBuilder::default()
.platform_variants(variants)
.build()?,
)
.await?;
let update_deployment = client
.container()
.from("kasperhermansen/update-deployment:1680472594")
.with_env_variable("GIT_USERNAME", "kjuulh")
.with_env_variable("GIT_PASSWORD", std::env::var("GIT_PASSWORD").unwrap())
.with_exec(vec![
"update-deployment",
"--repo",
"https://git.front.kjuulh.io/kjuulh/blog-deployment.git",
"--service",
"blog",
"--image",
&format!("kasperhermansen/kasperhermansen-blog:{tag}"),
])
.exit_code()
.await?;
Ok(())
}

8
deployment/Caddyfile Normal file
View File

@ -0,0 +1,8 @@
{
debug
}
http://blog.kasperhermansen.com {
root * /usr/share/caddy
file_server
}

View File

@ -9,7 +9,8 @@
"compile": "tailwindcss -i ./styles/styles.css -o ./static/styles/styles.css",
"compile:watch": "tailwindcss -i ./styles/styles.css -o ./static/styles/styles.css --watch=always",
"serve:watch": "zola serve --drafts",
"dev": "yarn compile:watch & yarn serve:watch"
"dev": "yarn compile:watch & yarn serve:watch",
"build": "cd ci && cargo build && cd .. && ./ci/target/debug/ci"
},
"dependencies": {
"@tailwindcss/typography": "^0.5.9",

View File

@ -629,6 +629,11 @@ html,
padding-right: 1rem;
}
.py-2 {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
.py-8 {
padding-top: 2rem;
padding-bottom: 2rem;
@ -1342,6 +1347,21 @@ html,
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.blog-content :is(:where(code):not(:where([class~="not-prose"] *))) {
--tw-text-opacity: 1;
color: rgba(var(--ctp-peach), var(--tw-text-opacity));
}
.blog-content :is(:where(ul):not(:where([class~="not-prose"] *))) {
--tw-text-opacity: 1;
color: rgb(243 244 246 / var(--tw-text-opacity));
}
.blog-content :is(:where(li):not(:where([class~="not-prose"] *))) {
--tw-text-opacity: 1;
color: rgb(243 244 246 / var(--tw-text-opacity));
}
.blog-summary {
color: var(--tw-prose-body);
max-width: 65ch;
@ -2044,6 +2064,21 @@ html,
color: rgb(209 213 219 / var(--tw-text-opacity));
}
.blog-summary :is(:where(code):not(:where([class~="not-prose"] *))) {
--tw-text-opacity: 1;
color: rgba(var(--ctp-peach), var(--tw-text-opacity));
}
.blog-summary :is(:where(ul):not(:where([class~="not-prose"] *))) {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
}
.blog-summary :is(:where(li):not(:where([class~="not-prose"] *))) {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
}
.blog-summary > p:first-child {
margin-top: 0px;
}

View File

@ -11,7 +11,16 @@
}
.blog-content {
@apply prose lg:prose-lg max-w-3xl prose-headings:text-peach prose-p:text-gray-100 prose-a:text-orange-200 prose-strong:text-white;
@apply prose
lg:prose-lg
max-w-3xl
prose-headings:text-peach
prose-p:text-gray-100
prose-a:text-orange-200
prose-li:text-gray-100
prose-ul:text-gray-100
prose-code:text-peach
prose-strong:text-white;
}
.blog-summary {
@ -21,6 +30,9 @@
prose-p:text-gray-400
prose-a:text-orange-300
prose-strong:text-gray-300
prose-li:text-gray-400
prose-ul:text-gray-400
prose-code:text-peach
pl-6
ml-6
border-l-2

View File

@ -11,11 +11,13 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="{{ get_url(path="styles/styles.css") | safe }}" />
<script defer data-domain="blog.kasperhermansen.com" src="https://plausible.front.kjuulh.io/js/script.js"></script>
</head>
<body>
<section class="section container mx-auto">
{% block content %} {% endblock %}
{% block content %} {% endblock %}
</section>
</body>

View File

@ -18,7 +18,7 @@
<br />
<div class="blog-summary ">
{% if page.description %}
{{ page.description }}
<p>{{ page.description }}</p>
{% elif page.summary %}
{{ page.summary | safe }}&hellip;
{% else %}

View File

@ -2,9 +2,12 @@
{% block content %}
{{ prev_macros::page_back_link(page=page) }}
<div class="mx-auto px-4 max-w-3xl py-8">
<div class="py-2">
{{ prev_macros::page_back_link(page=page) }}
</div>
<article class="blog-content">
<h1 class="title">
{{ page.title }}

View File

@ -1,16 +1,15 @@
{% extends "base.html" %}
{% block content %}
<div class="container mx-auto px-4 max-w-3xl py-8 space-y-4">
{% if section.ancestors | length > 0 %}
{{ prev_macros::section_back_link(section=section) }}
{% if section.ancestors | length > 0 %}
{{ prev_macros::section_back_link(section=section) }}
{% endif %}
{% if section.extra.section_path -%}
{% set section = get_section(path=section.extra.section_path) %}
{% set section = get_section(path=section.extra.section_path) %}
{% endif -%}
<h1 class="title text-peach text-3xl">
{{ section.title }}