initial commit of gitara site
10
.cargo/config.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[alias]
|
||||
loco = "run --"
|
||||
loco-tool = "run --"
|
||||
|
||||
playground = "run --example playground"
|
||||
|
||||
# https://github.com/rust-lang/rust/issues/141626
|
||||
# (can be removed once link.exe is fixed)
|
||||
[target.x86_64-pc-windows-msvc]
|
||||
linker = "rust-lld"
|
||||
19
.dockerignore
Normal file
@@ -0,0 +1,19 @@
|
||||
target
|
||||
node_modules
|
||||
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
docker-compose.prod.yml
|
||||
Makefile
|
||||
Caddyfile
|
||||
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
.env
|
||||
.env.*
|
||||
*.sqlite
|
||||
*.sqlite-*
|
||||
|
||||
uploads
|
||||
*report.html
|
||||
26
.env.production.example
Normal file
@@ -0,0 +1,26 @@
|
||||
CONTAINER_NAME=universal-web
|
||||
REVERSE_PROXY_NETWORK=
|
||||
UPLOADS_VOLUME_NAME=universal_web_uploads
|
||||
|
||||
APP_HOST=https://gitara.farmeris.sk
|
||||
PORT=5150
|
||||
SERVER_BINDING=0.0.0.0
|
||||
|
||||
DATABASE_URL=
|
||||
JWT_SECRET=
|
||||
|
||||
ADMIN_EMAIL=
|
||||
ADMIN_PASSWORD=
|
||||
ADMIN_NAME=Admin
|
||||
UPLOADS_ROOT=data/uploads
|
||||
|
||||
LOG_LEVEL=info
|
||||
LOG_FORMAT=compact
|
||||
|
||||
MAILER_STUB=true
|
||||
SMTP_ENABLE=false
|
||||
SMTP_HOST=localhost
|
||||
SMTP_PORT=1025
|
||||
SMTP_SECURE=false
|
||||
SMTP_USER=
|
||||
SMTP_PASSWORD=
|
||||
102
.github/workflows/ci.yaml
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
RUST_TOOLCHAIN: stable
|
||||
TOOLCHAIN_PROFILE: minimal
|
||||
|
||||
jobs:
|
||||
rustfmt:
|
||||
name: Check Style
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Checkout the code
|
||||
uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: ${{ env.RUST_TOOLCHAIN }}
|
||||
components: rustfmt
|
||||
- name: Run cargo fmt
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: --all -- --check
|
||||
|
||||
clippy:
|
||||
name: Run Clippy
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Checkout the code
|
||||
uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: ${{ env.RUST_TOOLCHAIN }}
|
||||
- name: Setup Rust cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
- name: Run cargo clippy
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: --all-features -- -D warnings -W clippy::pedantic -W clippy::nursery -W rust-2018-idioms
|
||||
|
||||
test:
|
||||
name: Run Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
services:
|
||||
redis:
|
||||
image: redis
|
||||
options: >-
|
||||
--health-cmd "redis-cli ping"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- "6379:6379"
|
||||
postgres:
|
||||
image: postgres
|
||||
env:
|
||||
POSTGRES_DB: postgres_test
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
ports:
|
||||
- "5432:5432"
|
||||
# Set health checks to wait until postgres has started
|
||||
options: --health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
|
||||
steps:
|
||||
- name: Checkout the code
|
||||
uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: ${{ env.RUST_TOOLCHAIN }}
|
||||
- name: Setup Rust cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
- name: Run cargo test
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --all-features --all
|
||||
env:
|
||||
REDIS_URL: redis://localhost:${{job.services.redis.ports[6379]}}
|
||||
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres_test
|
||||
|
||||
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
**/config/local.yaml
|
||||
**/config/*.local.yaml
|
||||
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# include cargo lock
|
||||
!Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
*.sqlite
|
||||
*.sqlite-*
|
||||
.env
|
||||
.env.production
|
||||
uploads/
|
||||
*.report.html
|
||||
favicon_io.zip
|
||||
2
.rustfmt.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
max_width = 100
|
||||
use_small_heuristics = "Default"
|
||||
14
Caddyfile
Normal file
@@ -0,0 +1,14 @@
|
||||
gitara.farmeris.sk {
|
||||
encode gzip
|
||||
|
||||
@static path /static/*
|
||||
header @static Cache-Control "public, max-age=2592000"
|
||||
|
||||
rewrite /favicon.ico /static/favicon/favicon.ico
|
||||
|
||||
reverse_proxy gitara-web:5150
|
||||
}
|
||||
|
||||
www.gitara.farmeris.sk {
|
||||
redir https://gitara.farmeris.sk{uri} permanent
|
||||
}
|
||||
5984
Cargo.lock
generated
Normal file
56
Cargo.toml
Normal file
@@ -0,0 +1,56 @@
|
||||
[workspace]
|
||||
|
||||
[package]
|
||||
name = "gitara_web"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
default-run = "gitara_web-cli"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[workspace.dependencies]
|
||||
loco-rs = { version = "0.16" }
|
||||
|
||||
[dependencies]
|
||||
loco-rs = { workspace = true }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1" }
|
||||
tokio = { version = "1.45", default-features = false, features = [
|
||||
"rt-multi-thread",
|
||||
] }
|
||||
async-trait = { version = "0.1" }
|
||||
axum = { version = "0.8", features = ["multipart"] }
|
||||
tracing = { version = "0.1" }
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
|
||||
regex = { version = "1.11" }
|
||||
migration = { path = "migration" }
|
||||
sea-orm = { version = "1.1", features = [
|
||||
"sqlx-sqlite",
|
||||
"sqlx-postgres",
|
||||
"runtime-tokio-rustls",
|
||||
"macros",
|
||||
] }
|
||||
chrono = { version = "0.4" }
|
||||
time = { version = "0.3" }
|
||||
dotenvy = { version = "0.15" }
|
||||
validator = { version = "0.20" }
|
||||
uuid = { version = "1.6", features = ["v4"] }
|
||||
include_dir = { version = "0.7" }
|
||||
# view engine i18n
|
||||
fluent-templates = { version = "0.13", features = ["tera"] }
|
||||
unic-langid = { version = "0.9" }
|
||||
# /view engine
|
||||
axum-extra = { version = "0.10", features = ["form"] }
|
||||
bytes = { version = "1" }
|
||||
|
||||
[[bin]]
|
||||
name = "gitara_web-cli"
|
||||
path = "src/bin/main.rs"
|
||||
required-features = []
|
||||
|
||||
[dev-dependencies]
|
||||
loco-rs = { workspace = true, features = ["testing"] }
|
||||
serial_test = { version = "3.1.1" }
|
||||
rstest = { version = "0.25" }
|
||||
insta = { version = "1.34", features = ["redactions", "yaml", "filters"] }
|
||||
25
Dockerfile
Normal file
@@ -0,0 +1,25 @@
|
||||
FROM rust:1-slim-bookworm AS builder
|
||||
|
||||
|
||||
WORKDIR /usr/src
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN cargo build --release --bin gitara_web-cli
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /usr/app
|
||||
|
||||
COPY --from=builder /usr/src/assets assets
|
||||
COPY --from=builder /usr/src/config config
|
||||
COPY --from=builder /usr/src/target/release/gitara_web-cli gitara_web-cli
|
||||
|
||||
ENV LOCO_ENV=production
|
||||
EXPOSE 5150
|
||||
ENTRYPOINT ["/usr/app/gitara_web-cli"]
|
||||
CMD ["start"]
|
||||
20
Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
COMPOSE = docker compose -f docker-compose.prod.yml --env-file .env.production
|
||||
|
||||
.PHONY: up down restart logs build ps
|
||||
|
||||
up:
|
||||
$(COMPOSE) up -d --build
|
||||
|
||||
down:
|
||||
$(COMPOSE) down
|
||||
|
||||
restart: down up
|
||||
|
||||
logs:
|
||||
$(COMPOSE) logs -f --tail=100
|
||||
|
||||
build:
|
||||
$(COMPOSE) build --no-cache
|
||||
|
||||
ps:
|
||||
$(COMPOSE) ps
|
||||
58
README.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Welcome to Loco :train:
|
||||
|
||||
[Loco](https://loco.rs) is a web and API framework running on Rust.
|
||||
|
||||
This is the **SaaS starter** which includes a `User` model and authentication based on JWT.
|
||||
It also include configuration sections that help you pick either a frontend or a server-side template set up for your fullstack server.
|
||||
|
||||
|
||||
## Quick Start
|
||||
|
||||
```sh
|
||||
cargo loco start
|
||||
```
|
||||
|
||||
```sh
|
||||
$ cargo loco start
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 21.63s
|
||||
Running `target/debug/myapp start`
|
||||
|
||||
:
|
||||
:
|
||||
:
|
||||
|
||||
controller/app_routes.rs:203: [Middleware] Adding log trace id
|
||||
|
||||
▄ ▀
|
||||
▀ ▄
|
||||
▄ ▀ ▄ ▄ ▄▀
|
||||
▄ ▀▄▄
|
||||
▄ ▀ ▀ ▀▄▀█▄
|
||||
▀█▄
|
||||
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▀▀█
|
||||
██████ █████ ███ █████ ███ █████ ███ ▀█
|
||||
██████ █████ ███ █████ ▀▀▀ █████ ███ ▄█▄
|
||||
██████ █████ ███ █████ █████ ███ ████▄
|
||||
██████ █████ ███ █████ ▄▄▄ █████ ███ █████
|
||||
██████ █████ ███ ████ ███ █████ ███ ████▀
|
||||
▀▀▀██▄ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ██▀
|
||||
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
|
||||
https://loco.rs
|
||||
|
||||
environment: development
|
||||
database: automigrate
|
||||
logger: debug
|
||||
compilation: debug
|
||||
modes: server
|
||||
|
||||
listening on http://localhost:5150
|
||||
```
|
||||
|
||||
## Full Stack Serving
|
||||
|
||||
You can check your [configuration](config/development.yaml) to pick either frontend setup or server-side rendered template, and activate the relevant configuration sections.
|
||||
|
||||
|
||||
## Getting help
|
||||
|
||||
Check out [a quick tour](https://loco.rs/docs/getting-started/tour/) or [the complete guide](https://loco.rs/docs/getting-started/guide/).
|
||||
9
assets/i18n/de-DE/main.ftl
Normal file
@@ -0,0 +1,9 @@
|
||||
hello-world = Hallo Welt!
|
||||
greeting = Hallochen { $name }!
|
||||
.placeholder = Hallo Freund!
|
||||
about = Uber
|
||||
image-size = Image size
|
||||
image-size-small = Small
|
||||
image-size-medium = Medium
|
||||
image-size-full = Full width
|
||||
image-width-px = Width px
|
||||
174
assets/i18n/en-US/main.ftl
Normal file
@@ -0,0 +1,174 @@
|
||||
brand = My guitar
|
||||
hello-world = Hello world!
|
||||
meta-description = A guitar player's personal site. News, blog posts, albums, and songs in one place.
|
||||
nav-home = Home
|
||||
nav-about = About
|
||||
nav-blog = Blog
|
||||
nav-audio = Albums
|
||||
nav-songs = Songs
|
||||
nav-admin = Admin
|
||||
admin-title = Admin
|
||||
admin-dashboard = Dashboard
|
||||
admin-blog = Blog
|
||||
admin-audio = Audio
|
||||
admin-about = About
|
||||
admin-exit = Exit
|
||||
view-site = View site
|
||||
admin-blog-desc = create and update blog articles.
|
||||
admin-about-desc = edit the public about page content.
|
||||
admin-audio-desc = upload songs, then group them into albums.
|
||||
logout = Log out
|
||||
settings = Settings
|
||||
settings-language = Language
|
||||
settings-theme = Theme
|
||||
language-en = English
|
||||
language-sk = Slovak
|
||||
menu = Menu
|
||||
theme-system = System
|
||||
theme-light = Light
|
||||
theme-dark = Dark
|
||||
home-title = Home
|
||||
home-sub = news and updates.
|
||||
home-all-posts = All posts
|
||||
home-recent = Recent posts
|
||||
home-picks = have a listen
|
||||
home-no-posts = no published posts yet
|
||||
blog-title = Blog
|
||||
blog-sub = published article(s)
|
||||
blog-manage = Manage
|
||||
blog-read = Read
|
||||
blog-no-posts = no published posts yet
|
||||
blog-views = views logged
|
||||
cd-up = cd ..
|
||||
about-sub = about this site.
|
||||
about-readonly = readonly
|
||||
audio-title = Audio
|
||||
audio-sub = published album(s)
|
||||
audio-all-songs = All songs
|
||||
audio-open = Open
|
||||
audio-play = Play
|
||||
audio-no-albums = no published albums yet
|
||||
songs-title = Songs
|
||||
songs-sub = track(s) across every album.
|
||||
songs-play-all = Play all
|
||||
songs-albums = Albums
|
||||
songs-no-tracks = no tracks yet
|
||||
album-by = by
|
||||
album-play-full = Play full album
|
||||
album-queue-all = queue all tracks in order
|
||||
album-no-tracks = no tracks yet
|
||||
login-title = Admin login
|
||||
login-error = Access denied - invalid email or password.
|
||||
login-root = root
|
||||
login-auth = Authenticate
|
||||
login-email = Email
|
||||
login-password = Password
|
||||
auth = Auth
|
||||
admin-session = Session
|
||||
readonly = readonly
|
||||
post = post
|
||||
album = album
|
||||
published = published
|
||||
draft = draft
|
||||
single = single
|
||||
manage = Manage
|
||||
open = Open
|
||||
play = Play
|
||||
new-article = New article
|
||||
edit = Edit
|
||||
delete = Delete
|
||||
save = Save
|
||||
cancel = Cancel
|
||||
create = Create
|
||||
upload = Upload
|
||||
view = View
|
||||
back-to-dashboard = Back to dashboard
|
||||
back-to-articles = Back to articles
|
||||
title = Title
|
||||
status = Status
|
||||
actions = Actions
|
||||
content = Content
|
||||
excerpt = Excerpt
|
||||
featured-image-id = Featured image id
|
||||
image-file = Image file
|
||||
uploaded-image-id = Uploaded image id
|
||||
url = URL
|
||||
upload-featured-image = Upload image
|
||||
image-upload-help = Upload an image here to use it as the article image.
|
||||
image-uploading = Uploading...
|
||||
image-uploaded = Image uploaded and selected.
|
||||
image-upload-error = Image upload failed.
|
||||
image-size = Image size
|
||||
image-size-small = Small
|
||||
image-size-medium = Medium
|
||||
image-size-full = Full width
|
||||
image-width-px = Width px
|
||||
admin-blog-articles = Blog articles
|
||||
admin-blog-index-desc = Create, edit, and remove blog posts.
|
||||
admin-blog-create-desc = Create a blog post for the public site.
|
||||
admin-no-articles = No articles yet.
|
||||
admin-create-first-post = Create the first blog post.
|
||||
edit-article = Edit article
|
||||
create-article = Create article
|
||||
edit-about = Edit About
|
||||
update-about-page = Update the public about page.
|
||||
view-page = View page
|
||||
albums-title = Albums
|
||||
new-album = New album
|
||||
admin-albums-desc = Step 2 - group songs into a release with a cover.
|
||||
admin-albums-before = Before you make an album
|
||||
admin-albums-step-upload = Upload your songs first - an album is built from songs that already exist.
|
||||
admin-albums-step-create = Create the album here, then tick the songs that belong to it.
|
||||
admin-no-albums = No albums yet
|
||||
admin-create-album-empty = Create an album to group your songs into a release.
|
||||
open-edit = Open and edit
|
||||
songs-title-admin = Songs
|
||||
admin-songs-desc = Step 1 - every audio file you upload becomes a song.
|
||||
upload-song = Upload song
|
||||
admin-audio-how = How audio works
|
||||
admin-audio-step-upload = Upload a song - pick an audio file here; it becomes a song you can publish.
|
||||
admin-audio-step-album = Make an album (optional) - group songs together with a cover and track order.
|
||||
admin-audio-note = A song can be published on its own or as part of an album.
|
||||
song = Song
|
||||
where = Where
|
||||
in-album = In an album
|
||||
publish = Publish
|
||||
unpublish = Unpublish
|
||||
featured = Featured
|
||||
remove-from-album = Remove from album
|
||||
admin-no-songs = No songs yet
|
||||
admin-upload-first-song = Upload your first audio file.
|
||||
admin-tracklist = Tracklist
|
||||
admin-add-existing-song = Add an existing song
|
||||
admin-existing-song-help = These are songs you have uploaded that are not in an album yet.
|
||||
admin-add-to-album = Add to album
|
||||
admin-album-empty = This album has no songs yet
|
||||
admin-album-empty-help = Upload a file into the album, or add an existing song above.
|
||||
admin-two-ways-title = Two ways to add a song to this album
|
||||
admin-two-ways-upload = Upload a new file straight into the album using the button above.
|
||||
admin-two-ways-pick = Pick an existing song that is not in any album yet.
|
||||
album-title-label = Album title *
|
||||
artist = Artist
|
||||
release-date = Release date
|
||||
cover-image = Cover image
|
||||
description = Description
|
||||
songs-in-album = Songs in this album
|
||||
admin-new-album-desc = Fill in the details, then tick the songs to include.
|
||||
cover-help = Optional - png, jpg, webp or gif; shown on the album page.
|
||||
free-songs-help = Only songs that are not in an album yet are shown.
|
||||
no-free-songs = No free songs to add.
|
||||
upload-song-first = Upload a song first
|
||||
create-empty-add-later = or create the album empty and add songs later.
|
||||
publish-album-now = Publish now - visitors can see this album.
|
||||
create-album = Create album
|
||||
upload-song-into-album = Upload song into album
|
||||
upload-song-title = Upload song
|
||||
upload-into-album-help = Goes straight into the album
|
||||
upload-single-help = Uploads as a standalone song. You can add it to an album later.
|
||||
audio-file = Audio file *
|
||||
audio-file-help = Required - mp3, wav, ogg, flac, aac, m4a or webm.
|
||||
title-help = Optional - leave blank to use the audio file's name.
|
||||
track-number = Track number
|
||||
track-number-help = Optional - this song's position in the album track list.
|
||||
featured-help = Highlight this song on the site
|
||||
publish-song-now = Publish now - visitors can see it.
|
||||
174
assets/i18n/en/main.ftl
Normal file
@@ -0,0 +1,174 @@
|
||||
brand = My guitar
|
||||
hello-world = Hello world!
|
||||
meta-description = A guitar player's personal site. News, blog posts, albums, and songs in one place.
|
||||
nav-home = Home
|
||||
nav-about = About
|
||||
nav-blog = Blog
|
||||
nav-audio = Albums
|
||||
nav-songs = Songs
|
||||
nav-admin = Admin
|
||||
admin-title = Admin
|
||||
admin-dashboard = Dashboard
|
||||
admin-blog = Blog
|
||||
admin-audio = Audio
|
||||
admin-about = About
|
||||
admin-exit = Exit
|
||||
view-site = View site
|
||||
admin-blog-desc = create and update blog articles.
|
||||
admin-about-desc = edit the public about page content.
|
||||
admin-audio-desc = upload songs, then group them into albums.
|
||||
logout = Log out
|
||||
settings = Settings
|
||||
settings-language = Language
|
||||
settings-theme = Theme
|
||||
language-en = English
|
||||
language-sk = Slovak
|
||||
menu = Menu
|
||||
theme-system = System
|
||||
theme-light = Light
|
||||
theme-dark = Dark
|
||||
home-title = Home
|
||||
home-sub = news and updates.
|
||||
home-all-posts = All posts
|
||||
home-recent = Recent posts
|
||||
home-picks = have a listen
|
||||
home-no-posts = no published posts yet
|
||||
blog-title = Blog
|
||||
blog-sub = published article(s)
|
||||
blog-manage = Manage
|
||||
blog-read = Read
|
||||
blog-no-posts = no published posts yet
|
||||
blog-views = views logged
|
||||
cd-up = cd ..
|
||||
about-sub = about this site.
|
||||
about-readonly = readonly
|
||||
audio-title = Audio
|
||||
audio-sub = published album(s)
|
||||
audio-all-songs = All songs
|
||||
audio-open = Open
|
||||
audio-play = Play
|
||||
audio-no-albums = no published albums yet
|
||||
songs-title = Songs
|
||||
songs-sub = track(s) across every album.
|
||||
songs-play-all = Play all
|
||||
songs-albums = Albums
|
||||
songs-no-tracks = no tracks yet
|
||||
album-by = by
|
||||
album-play-full = Play full album
|
||||
album-queue-all = queue all tracks in order
|
||||
album-no-tracks = no tracks yet
|
||||
login-title = Admin login
|
||||
login-error = Access denied - invalid email or password.
|
||||
login-root = root
|
||||
login-auth = Authenticate
|
||||
login-email = Email
|
||||
login-password = Password
|
||||
auth = Auth
|
||||
admin-session = Session
|
||||
readonly = readonly
|
||||
post = post
|
||||
album = album
|
||||
published = published
|
||||
draft = draft
|
||||
single = single
|
||||
manage = Manage
|
||||
open = Open
|
||||
play = Play
|
||||
new-article = New article
|
||||
edit = Edit
|
||||
delete = Delete
|
||||
save = Save
|
||||
cancel = Cancel
|
||||
create = Create
|
||||
upload = Upload
|
||||
view = View
|
||||
back-to-dashboard = Back to dashboard
|
||||
back-to-articles = Back to articles
|
||||
title = Title
|
||||
status = Status
|
||||
actions = Actions
|
||||
content = Content
|
||||
excerpt = Excerpt
|
||||
featured-image-id = Featured image id
|
||||
image-file = Image file
|
||||
uploaded-image-id = Uploaded image id
|
||||
url = URL
|
||||
upload-featured-image = Upload image
|
||||
image-upload-help = Upload an image here to use it as the article image.
|
||||
image-uploading = Uploading...
|
||||
image-uploaded = Image uploaded and selected.
|
||||
image-upload-error = Image upload failed.
|
||||
image-size = Image size
|
||||
image-size-small = Small
|
||||
image-size-medium = Medium
|
||||
image-size-full = Full width
|
||||
image-width-px = Width px
|
||||
admin-blog-articles = Blog articles
|
||||
admin-blog-index-desc = Create, edit, and remove blog posts.
|
||||
admin-blog-create-desc = Create a blog post for the public site.
|
||||
admin-no-articles = No articles yet.
|
||||
admin-create-first-post = Create the first blog post.
|
||||
edit-article = Edit article
|
||||
create-article = Create article
|
||||
edit-about = Edit About
|
||||
update-about-page = Update the public about page.
|
||||
view-page = View page
|
||||
albums-title = Albums
|
||||
new-album = New album
|
||||
admin-albums-desc = Step 2 - group songs into a release with a cover.
|
||||
admin-albums-before = Before you make an album
|
||||
admin-albums-step-upload = Upload your songs first - an album is built from songs that already exist.
|
||||
admin-albums-step-create = Create the album here, then tick the songs that belong to it.
|
||||
admin-no-albums = No albums yet
|
||||
admin-create-album-empty = Create an album to group your songs into a release.
|
||||
open-edit = Open and edit
|
||||
songs-title-admin = Songs
|
||||
admin-songs-desc = Step 1 - every audio file you upload becomes a song.
|
||||
upload-song = Upload song
|
||||
admin-audio-how = How audio works
|
||||
admin-audio-step-upload = Upload a song - pick an audio file here; it becomes a song you can publish.
|
||||
admin-audio-step-album = Make an album (optional) - group songs together with a cover and track order.
|
||||
admin-audio-note = A song can be published on its own or as part of an album.
|
||||
song = Song
|
||||
where = Where
|
||||
in-album = In an album
|
||||
publish = Publish
|
||||
unpublish = Unpublish
|
||||
featured = Featured
|
||||
remove-from-album = Remove from album
|
||||
admin-no-songs = No songs yet
|
||||
admin-upload-first-song = Upload your first audio file.
|
||||
admin-tracklist = Tracklist
|
||||
admin-add-existing-song = Add an existing song
|
||||
admin-existing-song-help = These are songs you have uploaded that are not in an album yet.
|
||||
admin-add-to-album = Add to album
|
||||
admin-album-empty = This album has no songs yet
|
||||
admin-album-empty-help = Upload a file into the album, or add an existing song above.
|
||||
admin-two-ways-title = Two ways to add a song to this album
|
||||
admin-two-ways-upload = Upload a new file straight into the album using the button above.
|
||||
admin-two-ways-pick = Pick an existing song that is not in any album yet.
|
||||
album-title-label = Album title *
|
||||
artist = Artist
|
||||
release-date = Release date
|
||||
cover-image = Cover image
|
||||
description = Description
|
||||
songs-in-album = Songs in this album
|
||||
admin-new-album-desc = Fill in the details, then tick the songs to include.
|
||||
cover-help = Optional - png, jpg, webp or gif; shown on the album page.
|
||||
free-songs-help = Only songs that are not in an album yet are shown.
|
||||
no-free-songs = No free songs to add.
|
||||
upload-song-first = Upload a song first
|
||||
create-empty-add-later = or create the album empty and add songs later.
|
||||
publish-album-now = Publish now - visitors can see this album.
|
||||
create-album = Create album
|
||||
upload-song-into-album = Upload song into album
|
||||
upload-song-title = Upload song
|
||||
upload-into-album-help = Goes straight into the album
|
||||
upload-single-help = Uploads as a standalone song. You can add it to an album later.
|
||||
audio-file = Audio file *
|
||||
audio-file-help = Required - mp3, wav, ogg, flac, aac, m4a or webm.
|
||||
title-help = Optional - leave blank to use the audio file's name.
|
||||
track-number = Track number
|
||||
track-number-help = Optional - this song's position in the album track list.
|
||||
featured-help = Highlight this song on the site
|
||||
publish-song-now = Publish now - visitors can see it.
|
||||
174
assets/i18n/sk/main.ftl
Normal file
@@ -0,0 +1,174 @@
|
||||
brand = Moja gitara
|
||||
hello-world = Ahoj svet!
|
||||
meta-description = Osobná stránka gitaristu. Novinky, blog, albumy a skladby na jednom mieste.
|
||||
nav-home = Domov
|
||||
nav-about = O mne
|
||||
nav-blog = Blog
|
||||
nav-audio = Albumy
|
||||
nav-songs = Skladby
|
||||
nav-admin = Admin
|
||||
admin-title = Administrácia
|
||||
admin-dashboard = Prehľad
|
||||
admin-blog = Blog
|
||||
admin-audio = Hudba
|
||||
admin-about = O mne
|
||||
admin-exit = Späť na web
|
||||
view-site = Zobraziť web
|
||||
admin-blog-desc = vytvoriť a upravovať blogové články.
|
||||
admin-about-desc = upraviť obsah verejnej stránky o mne.
|
||||
admin-audio-desc = nahrať skladby a potom ich zoskupiť do albumov.
|
||||
logout = Odhlásiť sa
|
||||
settings = Nastavenia
|
||||
settings-language = Jazyk
|
||||
settings-theme = Téma
|
||||
language-en = Angličtina
|
||||
language-sk = Slovenčina
|
||||
menu = Menu
|
||||
theme-system = Systém
|
||||
theme-light = Svetlý
|
||||
theme-dark = Tmavý
|
||||
home-title = Domov
|
||||
home-sub = novinky a aktuality.
|
||||
home-all-posts = Všetky príspevky
|
||||
home-recent = Posledné príspevky
|
||||
home-picks = vypočuj si
|
||||
home-no-posts = zatiaľ žiadne zverejnené príspevky
|
||||
blog-title = Blog
|
||||
blog-sub = zverejnené články
|
||||
blog-manage = Spravovať
|
||||
blog-read = Čítať
|
||||
blog-no-posts = zatiaľ žiadne zverejnené príspevky
|
||||
blog-views = zobrazení
|
||||
cd-up = cd ..
|
||||
about-sub = o tejto stránke.
|
||||
about-readonly = iba na čítanie
|
||||
audio-title = Hudba
|
||||
audio-sub = zverejnené albumy
|
||||
audio-all-songs = Všetky skladby
|
||||
audio-open = Otvoriť
|
||||
audio-play = Prehrať
|
||||
audio-no-albums = zatiaľ žiadne zverejnené albumy
|
||||
songs-title = Skladby
|
||||
songs-sub = skladieb naprieč všetkými albumami.
|
||||
songs-play-all = Prehrať všetko
|
||||
songs-albums = Albumy
|
||||
songs-no-tracks = zatiaľ žiadne skladby
|
||||
album-by = od
|
||||
album-play-full = Prehrať celý album
|
||||
album-queue-all = zoradiť všetky skladby v poradí
|
||||
album-no-tracks = zatiaľ žiadne skladby
|
||||
login-title = Prihlásenie admina
|
||||
login-error = Prístup odmietnutý - nesprávny e-mail alebo heslo.
|
||||
login-root = root
|
||||
login-auth = Prihlásiť sa
|
||||
login-email = E-mail
|
||||
login-password = Heslo
|
||||
auth = Overenie
|
||||
admin-session = Relácia
|
||||
readonly = iba na čítanie
|
||||
post = príspevok
|
||||
album = album
|
||||
published = zverejnené
|
||||
draft = koncept
|
||||
single = samostatne
|
||||
manage = Spravovať
|
||||
open = Otvoriť
|
||||
play = Prehrať
|
||||
new-article = Nový článok
|
||||
edit = Upraviť
|
||||
delete = Zmazať
|
||||
save = Uložiť
|
||||
cancel = Zrušiť
|
||||
create = Vytvoriť
|
||||
upload = Nahrať
|
||||
view = Zobraziť
|
||||
back-to-dashboard = Späť na prehľad
|
||||
back-to-articles = Späť na články
|
||||
title = Názov
|
||||
status = Stav
|
||||
actions = Akcie
|
||||
content = Obsah
|
||||
excerpt = Úryvok
|
||||
featured-image-id = ID hlavného obrázka
|
||||
image-file = Súbor obrázka
|
||||
uploaded-image-id = ID nahratého obrázka
|
||||
url = URL
|
||||
upload-featured-image = Nahrať obrázok
|
||||
image-upload-help = Tu nahraj obrázok, ktorý sa použije ako obrázok článku.
|
||||
image-uploading = Nahrávam...
|
||||
image-uploaded = Obrázok je nahratý a vybraný.
|
||||
image-upload-error = Nahratie obrázka zlyhalo.
|
||||
image-size = Veľkosť obrázka
|
||||
image-size-small = Malý
|
||||
image-size-medium = Stredný
|
||||
image-size-full = Na celú šírku
|
||||
image-width-px = Šírka px
|
||||
admin-blog-articles = Blogové články
|
||||
admin-blog-index-desc = Vytvárať, upravovať a odstraňovať blogové články.
|
||||
admin-blog-create-desc = Vytvoriť blogový článok pre verejný web.
|
||||
admin-no-articles = Zatiaľ žiadne články.
|
||||
admin-create-first-post = Vytvor prvý blogový článok.
|
||||
edit-article = Upraviť článok
|
||||
create-article = Vytvoriť článok
|
||||
edit-about = Upraviť O mne
|
||||
update-about-page = Upraviť verejnú stránku O mne.
|
||||
view-page = Zobraziť stránku
|
||||
albums-title = Albumy
|
||||
new-album = Nový album
|
||||
admin-albums-desc = Krok 2 - zoskupiť skladby do vydania s obalom.
|
||||
admin-albums-before = Pred vytvorením albumu
|
||||
admin-albums-step-upload = Najprv nahraj skladby - album sa skladá zo skladieb, ktoré už existujú.
|
||||
admin-albums-step-create = Tu vytvor album a potom označ skladby, ktoré doň patria.
|
||||
admin-no-albums = Zatiaľ žiadne albumy
|
||||
admin-create-album-empty = Vytvor album, do ktorého zoskupíš skladby.
|
||||
open-edit = Otvoriť a upraviť
|
||||
songs-title-admin = Skladby
|
||||
admin-songs-desc = Krok 1 - každý nahratý zvukový súbor sa stane skladbou.
|
||||
upload-song = Nahrať skladbu
|
||||
admin-audio-how = Ako funguje hudba
|
||||
admin-audio-step-upload = Nahraj skladbu - vyber zvukový súbor, ktorý potom môžeš zverejniť.
|
||||
admin-audio-step-album = Vytvor album (voliteľné) - zoskup skladby s obalom a poradím.
|
||||
admin-audio-note = Skladba môže byť zverejnená samostatne alebo ako súčasť albumu.
|
||||
song = Skladba
|
||||
where = Kde
|
||||
in-album = V albume
|
||||
publish = Zverejniť
|
||||
unpublish = Stiahnuť
|
||||
featured = Zvýraznené
|
||||
remove-from-album = Odstrániť z albumu
|
||||
admin-no-songs = Zatiaľ žiadne skladby
|
||||
admin-upload-first-song = Nahraj prvý zvukový súbor.
|
||||
admin-tracklist = Zoznam skladieb
|
||||
admin-add-existing-song = Pridať existujúcu skladbu
|
||||
admin-existing-song-help = Toto sú skladby, ktoré ešte nie sú v albume.
|
||||
admin-add-to-album = Pridať do albumu
|
||||
admin-album-empty = Tento album zatiaľ nemá skladby
|
||||
admin-album-empty-help = Nahraj súbor do albumu alebo pridaj existujúcu skladbu vyššie.
|
||||
admin-two-ways-title = Dva spôsoby, ako pridať skladbu do albumu
|
||||
admin-two-ways-upload = Nahraj nový súbor priamo do albumu pomocou tlačidla vyššie.
|
||||
admin-two-ways-pick = Vyber existujúcu skladbu, ktorá ešte nie je v albume.
|
||||
album-title-label = Názov albumu *
|
||||
artist = Interpret
|
||||
release-date = Dátum vydania
|
||||
cover-image = Obrázok obalu
|
||||
description = Popis
|
||||
songs-in-album = Skladby v albume
|
||||
admin-new-album-desc = Vyplň údaje a potom označ skladby, ktoré chceš zahrnúť.
|
||||
cover-help = Voliteľné - png, jpg, webp alebo gif; zobrazí sa na stránke albumu.
|
||||
free-songs-help = Zobrazujú sa iba skladby, ktoré ešte nie sú v albume.
|
||||
no-free-songs = Žiadne voľné skladby na pridanie.
|
||||
upload-song-first = Najprv nahraj skladbu
|
||||
create-empty-add-later = alebo vytvor prázdny album a skladby pridaj neskôr.
|
||||
publish-album-now = Zverejniť teraz - návštevníci uvidia tento album.
|
||||
create-album = Vytvoriť album
|
||||
upload-song-into-album = Nahrať skladbu do albumu
|
||||
upload-song-title = Nahrať skladbu
|
||||
upload-into-album-help = Skladba pôjde priamo do albumu
|
||||
upload-single-help = Nahrá sa ako samostatná skladba. Do albumu ju môžeš pridať neskôr.
|
||||
audio-file = Zvukový súbor *
|
||||
audio-file-help = Povinné - mp3, wav, ogg, flac, aac, m4a alebo webm.
|
||||
title-help = Voliteľné - nechaj prázdne, ak chceš použiť názov zvukového súboru.
|
||||
track-number = Číslo skladby
|
||||
track-number-help = Voliteľné - pozícia skladby v zozname albumu.
|
||||
featured-help = Zvýrazniť túto skladbu na webe
|
||||
publish-song-now = Zverejniť teraz - návštevníci ju uvidia.
|
||||
1
assets/i18n_shared/shared.ftl
Normal file
@@ -0,0 +1 @@
|
||||
-something = foo
|
||||
3
assets/static/404.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<html><body>
|
||||
not found :-(
|
||||
</body></html>
|
||||
2
assets/static/css/app.css
Normal file
781
assets/static/css/theme.css
Normal file
@@ -0,0 +1,781 @@
|
||||
/* ============================================================
|
||||
* Terminal theme
|
||||
* ------------------------------------------------------------
|
||||
* Project-owned styling. The vendored `app.css` (a pre-compiled
|
||||
* Tailwind + DaisyUI bundle) is NOT edited. This file loads
|
||||
* after it (see base.html / admin/base.html) and provides:
|
||||
*
|
||||
* 1. Catppuccin Latte for DaisyUI's `light` theme
|
||||
* and Gruvbox for DaisyUI's `dark` theme
|
||||
* 2. square corners (terminals have none)
|
||||
* 3. a terminal look & feel: monospace, window chrome,
|
||||
* vim-style statusline, CRT scanlines
|
||||
* 4. `.term-*` building blocks used by the templates
|
||||
*
|
||||
* Why CSS classes and not utility classes: `app.css` is frozen
|
||||
* and only contains the utilities the original project used, so
|
||||
* new Tailwind classes would not exist. The DaisyUI *components*
|
||||
* (card/btn/badge/menu/...) do exist and are reused; everything
|
||||
* else is defined here as real, themeable CSS.
|
||||
*
|
||||
* Palettes:
|
||||
* - https://github.com/catppuccin/catppuccin (Latte)
|
||||
* - https://github.com/morhetz/gruvbox (dark, bright)
|
||||
* DaisyUI color vars are OKLch "L% C H" triplets; this file can
|
||||
* therefore tint anything with `oklch(var(--x) / <alpha>)`.
|
||||
* ============================================================ */
|
||||
|
||||
/* === 1. Theme palettes ====================================== */
|
||||
/* Catppuccin Latte. */
|
||||
[data-theme="light"] {
|
||||
--b1: 95.78% 0.006 264.5; /* #eff1f5 base */
|
||||
--b2: 93.35% 0.009 264.5; /* #e6e9ef mantle */
|
||||
--b3: 90.60% 0.012 264.5; /* #dce0e8 crust */
|
||||
--bc: 43.55% 0.043 279.3; /* #4c4f69 text */
|
||||
|
||||
--n: 80.83% 0.017 271.2; /* #bcc0cc surface1 */
|
||||
--nc: 43.55% 0.043 279.3; /* #4c4f69 text */
|
||||
|
||||
--p: 55.86% 0.226 262.1; /* #1e66f5 blue primary */
|
||||
--pc: 95.78% 0.006 264.5; /* #eff1f5 text on primary */
|
||||
--s: 55.47% 0.250 297.0; /* #8839ef mauve secondary */
|
||||
--sc: 95.78% 0.006 264.5; /* #eff1f5 text on secondary */
|
||||
--a: 60.23% 0.098 201.1; /* #179299 teal accent */
|
||||
--ac: 95.78% 0.006 264.5; /* #eff1f5 text on accent */
|
||||
|
||||
--in: 68.20% 0.145 235.4; /* #04a5e5 sky info */
|
||||
--su: 62.50% 0.177 140.4; /* #40a02b green success */
|
||||
--wa: 71.40% 0.149 67.8; /* #df8e1d yellow warning */
|
||||
--er: 55.05% 0.216 19.8; /* #d20f39 red error */
|
||||
--inc: 43.55% 0.043 279.3; /* #4c4f69 text on status */
|
||||
--suc: 95.78% 0.006 264.5;
|
||||
--wac: 95.78% 0.006 264.5;
|
||||
--erc: 95.78% 0.006 264.5;
|
||||
}
|
||||
|
||||
/* Source hex noted per line. To retune: change hex, reconvert
|
||||
* to OKLch, update the value. */
|
||||
[data-theme="dark"] {
|
||||
--b1: 27.69% 0 0; /* #282828 bg0 screen background */
|
||||
--b2: 31.10% 0.003 49.7; /* #32302f bg0_s panels / chrome */
|
||||
--b3: 34.40% 0.0066 48.7; /* #3c3836 bg1 borders */
|
||||
--bc: 89.42% 0.0566 89.5; /* #ebdbb2 fg body text */
|
||||
|
||||
--n: 34.40% 0.0066 48.7; /* #3c3836 bg1 */
|
||||
--nc: 89.42% 0.0566 89.5; /* #ebdbb2 fg */
|
||||
|
||||
--p: 73.10% 0.182 51.7; /* #fe8019 bright orange primary */
|
||||
--pc: 27.69% 0 0; /* #282828 text on primary */
|
||||
--s: 70.54% 0.097 2.3; /* #d3869b bright purple secondary */
|
||||
--sc: 27.69% 0 0; /* #282828 text on secondary */
|
||||
--a: 75.57% 0.108 137.6; /* #8ec07c bright aqua accent */
|
||||
--ac: 27.69% 0 0; /* #282828 text on accent */
|
||||
|
||||
--in: 69.26% 0.042 169.8; /* #83a598 bright blue info */
|
||||
--su: 76.52% 0.158 110.8; /* #b8bb26 bright green success */
|
||||
--wa: 83.49% 0.160 83.6; /* #fabd2f bright yellow warning */
|
||||
--er: 65.97% 0.217 30.4; /* #fb4934 bright red error */
|
||||
--inc: 24.07% 0.005 220.9; /* #1d2021 bg0_h text on status */
|
||||
--suc: 24.07% 0.005 220.9;
|
||||
--wac: 24.07% 0.005 220.9;
|
||||
--erc: 24.07% 0.005 220.9;
|
||||
}
|
||||
|
||||
/* === 2. Square corners ====================================== */
|
||||
/* `[data-theme]` matches the same <html> element as the vendored
|
||||
* `[data-theme=dark|light]` rules with equal specificity, and
|
||||
* wins by load order. Applies to both themes. */
|
||||
[data-theme] {
|
||||
--rounded-box: 0;
|
||||
--rounded-btn: 0;
|
||||
--rounded-badge: 0;
|
||||
--tab-radius: 0;
|
||||
--animation-btn: 0;
|
||||
--animation-input: 0;
|
||||
}
|
||||
|
||||
/* === 3. Terminal look & feel ================================ */
|
||||
/* Root font-size drives every rem in this file and in app.css.
|
||||
* Bump this to scale the whole UI; drop to shrink. */
|
||||
html { font-size: 19px; }
|
||||
body {
|
||||
font-family: "JetBrains Mono", "Cascadia Code", "Fira Code",
|
||||
ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
|
||||
font-size: 1rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* Text selection + scrollbars */
|
||||
[data-theme="light"] ::selection { background: #acb0be; color: #4c4f69; }
|
||||
[data-theme="light"] { scrollbar-color: #bcc0cc #eff1f5; }
|
||||
[data-theme="light"] ::-webkit-scrollbar { width: 12px; height: 12px; }
|
||||
[data-theme="light"] ::-webkit-scrollbar-track { background: #eff1f5; }
|
||||
[data-theme="light"] ::-webkit-scrollbar-thumb {
|
||||
background: #bcc0cc; border: 3px solid #eff1f5;
|
||||
}
|
||||
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #acb0be; }
|
||||
|
||||
[data-theme="dark"] ::selection { background: #fe8019; color: #282828; }
|
||||
[data-theme="dark"] { scrollbar-color: #504945 #282828; }
|
||||
[data-theme="dark"] ::-webkit-scrollbar { width: 12px; height: 12px; }
|
||||
[data-theme="dark"] ::-webkit-scrollbar-track { background: #282828; }
|
||||
[data-theme="dark"] ::-webkit-scrollbar-thumb {
|
||||
background: #504945; border: 3px solid #282828;
|
||||
}
|
||||
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #665c54; }
|
||||
|
||||
/* Faint CRT scanlines — dark only. Remove this block to drop it. */
|
||||
[data-theme="dark"] body::before {
|
||||
content: "";
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 90;
|
||||
pointer-events: none;
|
||||
background: repeating-linear-gradient(
|
||||
0deg, rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.15) 1px,
|
||||
transparent 1px, transparent 3px);
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
/* --- color helpers (theme-adaptive: gruvbox in dark) -------- */
|
||||
.t-orange { color: oklch(var(--p)); }
|
||||
.t-purple { color: oklch(var(--s)); }
|
||||
.t-aqua { color: oklch(var(--a)); }
|
||||
.t-blue { color: oklch(var(--in)); }
|
||||
.t-green { color: oklch(var(--su)); }
|
||||
.t-yellow { color: oklch(var(--wa)); }
|
||||
.t-red { color: oklch(var(--er)); }
|
||||
.t-dim { color: oklch(var(--bc) / 0.75); }
|
||||
|
||||
/* --- window titlebar (the header) -------------------------- */
|
||||
.term-titlebar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 50;
|
||||
background: oklch(var(--b2));
|
||||
border-bottom: 1px solid oklch(var(--b3));
|
||||
}
|
||||
.term-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.85rem;
|
||||
width: 100%;
|
||||
max-width: 72rem;
|
||||
margin: 0 auto;
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
.term-dots { display: inline-flex; gap: 0.45rem; flex: none; }
|
||||
.term-dot {
|
||||
width: 0.72rem;
|
||||
height: 0.72rem;
|
||||
border-radius: 9999px;
|
||||
display: block;
|
||||
}
|
||||
.term-dot.r { background: oklch(var(--er)); }
|
||||
.term-dot.y { background: oklch(var(--wa)); }
|
||||
.term-dot.g { background: oklch(var(--su)); }
|
||||
.term-brand {
|
||||
font-size: 0.85rem;
|
||||
white-space: nowrap;
|
||||
text-decoration: none;
|
||||
}
|
||||
.term-brand:hover { text-decoration: none; }
|
||||
.term-nav-right { margin-left: auto; display: flex; align-items: center; gap: 0.25rem; }
|
||||
|
||||
/* horizontal nav links */
|
||||
.term-navlinks { padding: 0; gap: 0; }
|
||||
.term-navlinks li > a,
|
||||
.term-navlinks li > form > button {
|
||||
padding: 0.2rem 0.55rem;
|
||||
font-size: 0.85rem;
|
||||
border-radius: 0;
|
||||
}
|
||||
.term-navlinks li > a::before { content: ""; }
|
||||
.term-navlinks li > a:hover,
|
||||
.term-navlinks li > form > button:hover {
|
||||
background: transparent;
|
||||
color: oklch(var(--p));
|
||||
}
|
||||
.term-navlinks a.is-active {
|
||||
color: oklch(var(--p));
|
||||
background: oklch(var(--p) / 0.12);
|
||||
}
|
||||
.term-navlinks a.is-active::before {
|
||||
content: "▸ ";
|
||||
color: oklch(var(--p));
|
||||
}
|
||||
|
||||
/* --- page body layout -------------------------------------- */
|
||||
.term-main {
|
||||
flex: 1 1 auto;
|
||||
width: 100%;
|
||||
max-width: 72rem;
|
||||
margin: 0 auto;
|
||||
padding: 2.25rem 1rem 3rem;
|
||||
}
|
||||
|
||||
/* --- command-prompt page heading --------------------------- */
|
||||
.term-cmd {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1.75rem;
|
||||
padding-bottom: 0.85rem;
|
||||
border-bottom: 1px solid oklch(var(--b3));
|
||||
}
|
||||
.term-cmd-line { font-size: 0.8rem; color: oklch(var(--bc) / 0.85); }
|
||||
.term-title {
|
||||
margin-top: 0.4rem;
|
||||
font-size: 1.7rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.15;
|
||||
color: oklch(var(--p));
|
||||
}
|
||||
.term-sub { margin-top: 0.2rem; font-size: 0.85rem; color: oklch(var(--bc) / 0.8); }
|
||||
.term-cmd-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
|
||||
|
||||
/* --- responsive card grid ---------------------------------- */
|
||||
.term-grid {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
|
||||
}
|
||||
.term-stack > * + * { margin-top: 1rem; }
|
||||
|
||||
/* --- cards as terminal windows ----------------------------- */
|
||||
.card {
|
||||
background: oklch(var(--b2));
|
||||
border: 1px solid oklch(var(--b3));
|
||||
box-shadow: none;
|
||||
}
|
||||
.card:hover { border-color: oklch(var(--p) / 0.5); }
|
||||
/* filename strip at the top of a card */
|
||||
.term-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.4rem 0.85rem;
|
||||
font-size: 0.74rem;
|
||||
color: oklch(var(--bc) / 0.6);
|
||||
background: oklch(var(--b1));
|
||||
border-bottom: 1px solid oklch(var(--b3));
|
||||
}
|
||||
.term-head .term-dots .term-dot { width: 0.55rem; height: 0.55rem; }
|
||||
.term-head-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.term-head-meta { margin-left: auto; }
|
||||
.card-title a { color: oklch(var(--p)); text-decoration: none; }
|
||||
.card-title a:hover { text-decoration: underline; }
|
||||
|
||||
/* --- inline tags ------------------------------------------- */
|
||||
.term-tag {
|
||||
display: inline-block;
|
||||
padding: 0.02rem 0.45rem;
|
||||
font-size: 0.7rem;
|
||||
letter-spacing: 0.03em;
|
||||
border: 1px solid oklch(var(--p) / 0.55);
|
||||
color: oklch(var(--p));
|
||||
}
|
||||
.term-tag.is-aqua { border-color: oklch(var(--a) / 0.55); color: oklch(var(--a)); }
|
||||
.term-tag.is-purple { border-color: oklch(var(--s) / 0.55); color: oklch(var(--s)); }
|
||||
.term-tag.is-blue { border-color: oklch(var(--in) / 0.55); color: oklch(var(--in)); }
|
||||
.term-tag.is-green { border-color: oklch(var(--su) / 0.55); color: oklch(var(--su)); }
|
||||
|
||||
/* --- empty / "no results" state ---------------------------- */
|
||||
.term-empty {
|
||||
padding: 2.25rem 1rem;
|
||||
text-align: center;
|
||||
color: oklch(var(--bc) / 0.6);
|
||||
border: 1px dashed oklch(var(--b3));
|
||||
}
|
||||
.term-empty-cmd { font-size: 0.8rem; color: oklch(var(--bc) / 0.45); }
|
||||
|
||||
/* --- how-it-works note + form helpers (admin) -------------- */
|
||||
.term-note {
|
||||
margin-bottom: 1.5rem;
|
||||
padding: 0.9rem 1.1rem;
|
||||
background: oklch(var(--b2));
|
||||
border: 1px solid oklch(var(--b3));
|
||||
border-left: 3px solid oklch(var(--a));
|
||||
}
|
||||
.term-note-title { margin-bottom: 0.55rem; font-size: 0.8rem; color: oklch(var(--a)); }
|
||||
.term-step { display: flex; gap: 0.55rem; font-size: 0.88rem; }
|
||||
.term-step + .term-step { margin-top: 0.3rem; }
|
||||
.term-step-n { flex: none; color: oklch(var(--p)); }
|
||||
.term-note-foot { margin-top: 0.6rem; font-size: 0.8rem; color: oklch(var(--bc) / 0.6); }
|
||||
.term-help { margin-top: 0.2rem; font-size: 0.76rem; color: oklch(var(--bc) / 0.55); }
|
||||
.term-picklist {
|
||||
border: 1px solid oklch(var(--b3));
|
||||
background: oklch(var(--b1));
|
||||
max-height: 18rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.term-pick {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.65rem;
|
||||
padding: 0.5rem 0.7rem;
|
||||
border-top: 1px solid oklch(var(--b3));
|
||||
cursor: pointer;
|
||||
}
|
||||
.term-pick:first-child { border-top: 0; }
|
||||
.term-pick:hover { background: oklch(var(--b2)); }
|
||||
.term-formdiv { margin: 1.25rem 0; border-top: 1px dashed oklch(var(--b3)); }
|
||||
|
||||
/* --- terminal session block (mockup-code substitute) ------- */
|
||||
.term-screen {
|
||||
background: oklch(var(--b1));
|
||||
border: 1px solid oklch(var(--b3));
|
||||
padding: 0.85rem 1rem;
|
||||
font-size: 0.85rem;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.term-screen .line { white-space: pre-wrap; }
|
||||
.term-screen .line::before {
|
||||
content: attr(data-p) " ";
|
||||
color: oklch(var(--su));
|
||||
}
|
||||
.term-screen .line.out::before { content: ""; }
|
||||
.term-screen .line.out { color: oklch(var(--bc) / 0.8); }
|
||||
|
||||
/* --- prose (article / about bodies) ------------------------ */
|
||||
.term-prose { line-height: 1.7; }
|
||||
.term-prose a { color: oklch(var(--in)); }
|
||||
|
||||
/* --- audio rows -------------------------------------------- */
|
||||
.term-track {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.7rem;
|
||||
padding: 0.5rem 0;
|
||||
border-top: 1px solid oklch(var(--b3));
|
||||
}
|
||||
.term-track:first-child { border-top: 0; }
|
||||
.term-track .btn { flex: none; }
|
||||
.term-track-name { font-size: 0.9rem; }
|
||||
/* "play album" row sitting above the per-track list */
|
||||
.term-track-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.7rem;
|
||||
padding-bottom: 0.65rem;
|
||||
margin-bottom: 0.15rem;
|
||||
border-bottom: 1px solid oklch(var(--b3));
|
||||
}
|
||||
.term-track-bar .btn { flex: none; }
|
||||
|
||||
/* --- persistent audio player bar --------------------------- */
|
||||
/* Hidden until the first song plays; shown by adding `uw-playing`
|
||||
* to <html>. The bar itself carries `hx-preserve` so the <audio>
|
||||
* keeps playing while htmx swaps the page around it. */
|
||||
#uw-player { display: none; }
|
||||
.uw-playing #uw-player {
|
||||
display: block;
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 80;
|
||||
background: oklch(var(--b2));
|
||||
border-top: 3px solid oklch(var(--p));
|
||||
box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
.uw-playing body { padding-bottom: 6.75rem; }
|
||||
.uw-player-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.15rem;
|
||||
width: 100%;
|
||||
max-width: 72rem;
|
||||
margin: 0 auto;
|
||||
padding: 1rem 1.5rem;
|
||||
}
|
||||
.uw-player-tag {
|
||||
flex: none;
|
||||
font-size: 0.98rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.02em;
|
||||
color: oklch(var(--p));
|
||||
white-space: nowrap;
|
||||
}
|
||||
.uw-player-title {
|
||||
flex: none;
|
||||
max-width: 24rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 1.1rem;
|
||||
color: oklch(var(--bc));
|
||||
}
|
||||
#uw-audio {
|
||||
flex: 1;
|
||||
min-width: 9rem;
|
||||
width: auto;
|
||||
height: 3.25rem;
|
||||
margin: 0;
|
||||
}
|
||||
.uw-player-close {
|
||||
flex: none;
|
||||
width: 2.85rem;
|
||||
height: 2.85rem;
|
||||
font-size: 1.05rem;
|
||||
background: transparent;
|
||||
border: 1px solid oklch(var(--b3));
|
||||
color: oklch(var(--bc) / 0.7);
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
}
|
||||
.uw-player-close:hover { color: oklch(var(--er)); border-color: oklch(var(--er)); }
|
||||
/* transport + playlist toggle buttons in the player bar */
|
||||
.uw-player-btn {
|
||||
flex: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.3rem;
|
||||
min-width: 2.85rem;
|
||||
height: 2.85rem;
|
||||
padding: 0 0.6rem;
|
||||
font-size: 1.05rem;
|
||||
background: transparent;
|
||||
border: 1px solid oklch(var(--b3));
|
||||
color: oklch(var(--bc) / 0.78);
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
}
|
||||
.uw-player-btn:hover { color: oklch(var(--p)); border-color: oklch(var(--p)); }
|
||||
.uw-queue-badge {
|
||||
font-size: 0.72rem;
|
||||
font-weight: 700;
|
||||
min-width: 1.25rem;
|
||||
padding: 0.05rem 0.3rem;
|
||||
background: oklch(var(--p));
|
||||
color: oklch(var(--pc));
|
||||
}
|
||||
#uw-player:not(.uw-has-queue) .uw-queue-badge { display: none; }
|
||||
|
||||
/* --- the SoundCloud-style playlist panel ------------------- */
|
||||
.uw-queue {
|
||||
width: 100%;
|
||||
max-width: 72rem;
|
||||
margin: 0 auto;
|
||||
border-bottom: 1px solid oklch(var(--b3));
|
||||
}
|
||||
.uw-queue[hidden] { display: none; }
|
||||
.uw-queue-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
padding: 0.6rem 1.5rem;
|
||||
border-bottom: 1px solid oklch(var(--b3));
|
||||
}
|
||||
.uw-queue-title { font-weight: 700; font-size: 0.95rem; color: oklch(var(--p)); }
|
||||
.uw-queue-meta { font-size: 0.8rem; color: oklch(var(--bc) / 0.6); }
|
||||
.uw-queue-clear {
|
||||
margin-left: auto;
|
||||
padding: 0.25rem 0.6rem;
|
||||
font-size: 0.8rem;
|
||||
background: transparent;
|
||||
border: 1px solid oklch(var(--b3));
|
||||
color: oklch(var(--bc) / 0.7);
|
||||
cursor: pointer;
|
||||
}
|
||||
.uw-queue-clear:hover { color: oklch(var(--er)); border-color: oklch(var(--er)); }
|
||||
.uw-queue-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0.35rem 0;
|
||||
max-height: 15rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.uw-queue-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.7rem;
|
||||
padding: 0.4rem 1.5rem;
|
||||
}
|
||||
.uw-queue-item:hover { background: oklch(var(--b3) / 0.5); }
|
||||
.uw-queue-item.is-current { background: oklch(var(--p) / 0.12); }
|
||||
.uw-queue-jump {
|
||||
flex: none;
|
||||
width: 1.85rem;
|
||||
height: 1.85rem;
|
||||
font-size: 0.8rem;
|
||||
background: transparent;
|
||||
border: 1px solid oklch(var(--b3));
|
||||
color: oklch(var(--bc) / 0.7);
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
}
|
||||
.uw-queue-item.is-current .uw-queue-jump { color: oklch(var(--p)); border-color: oklch(var(--p)); }
|
||||
.uw-queue-name {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.uw-queue-item.is-current .uw-queue-name { color: oklch(var(--p)); font-weight: 600; }
|
||||
.uw-queue-remove {
|
||||
flex: none;
|
||||
width: 1.85rem;
|
||||
height: 1.85rem;
|
||||
font-size: 0.8rem;
|
||||
background: transparent;
|
||||
border: 1px solid transparent;
|
||||
color: oklch(var(--bc) / 0.5);
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
}
|
||||
.uw-queue-remove:hover { color: oklch(var(--er)); border-color: oklch(var(--er)); }
|
||||
|
||||
@media (max-width: 640px) {
|
||||
/* Two-row layout: [title][prev][next][queue][close] on top,
|
||||
* full-width <audio> scrubber underneath. */
|
||||
.uw-player-tag { display: none; }
|
||||
.uw-player-inner {
|
||||
flex-wrap: wrap;
|
||||
padding: 0.6rem 0.75rem;
|
||||
gap: 0.4rem;
|
||||
row-gap: 0.5rem;
|
||||
}
|
||||
.uw-player-title {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.uw-player-btn {
|
||||
min-width: 2.2rem;
|
||||
height: 2.2rem;
|
||||
padding: 0 0.35rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.uw-player-close { width: 2.2rem; height: 2.2rem; font-size: 0.95rem; }
|
||||
#uw-audio {
|
||||
order: 99;
|
||||
flex: 1 1 100%;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
height: 2.4rem;
|
||||
}
|
||||
.uw-playing body { padding-bottom: 8.25rem; }
|
||||
.uw-queue-head, .uw-queue-item { padding-left: 0.95rem; padding-right: 0.95rem; }
|
||||
}
|
||||
|
||||
/* --- vim-style statusline (the footer) --------------------- */
|
||||
.term-statusline {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: stretch;
|
||||
font-size: 0.72rem;
|
||||
border-top: 1px solid oklch(var(--b3));
|
||||
}
|
||||
.term-seg {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0.25rem 0.8rem;
|
||||
background: oklch(var(--b3));
|
||||
color: oklch(var(--bc));
|
||||
white-space: nowrap;
|
||||
}
|
||||
.term-seg.is-mode {
|
||||
background: oklch(var(--p));
|
||||
color: oklch(var(--pc));
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.06em;
|
||||
}
|
||||
.term-seg.is-alt {
|
||||
background: oklch(var(--s));
|
||||
color: oklch(var(--sc));
|
||||
font-weight: 700;
|
||||
}
|
||||
.term-seg.is-fill {
|
||||
flex: 1 1 8rem;
|
||||
background: oklch(var(--b2));
|
||||
color: oklch(var(--bc) / 0.55);
|
||||
}
|
||||
|
||||
/* --- square the icon buttons ------------------------------- */
|
||||
.btn-circle { border-radius: 0; }
|
||||
|
||||
/* --- blog editor ------------------------------------------- */
|
||||
.blog-editor {
|
||||
min-height: 24rem;
|
||||
background: oklch(var(--b1));
|
||||
}
|
||||
.blog-editor .ql-editor {
|
||||
min-height: 24rem;
|
||||
font-size: 1rem;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.ql-toolbar.ql-snow,
|
||||
.ql-container.ql-snow {
|
||||
border-color: oklch(var(--b3));
|
||||
}
|
||||
.ql-toolbar.ql-snow {
|
||||
background: oklch(var(--b2));
|
||||
}
|
||||
.ql-snow .ql-stroke,
|
||||
.ql-snow .ql-stroke-miter {
|
||||
stroke: oklch(var(--bc));
|
||||
}
|
||||
.ql-snow .ql-fill,
|
||||
.ql-snow .ql-stroke.ql-fill {
|
||||
fill: oklch(var(--bc));
|
||||
}
|
||||
.ql-snow .ql-picker,
|
||||
.ql-snow .ql-picker-options {
|
||||
color: oklch(var(--bc));
|
||||
}
|
||||
.ql-snow .ql-picker-options {
|
||||
background: oklch(var(--b1));
|
||||
border-color: oklch(var(--b3));
|
||||
}
|
||||
.ql-toolbar.ql-snow .ql-picker.ql-expanded .ql-picker-label,
|
||||
.ql-toolbar.ql-snow .ql-picker.ql-expanded .ql-picker-options {
|
||||
border-color: oklch(var(--b3));
|
||||
}
|
||||
/* active / hover toolbar state -> gruvbox accent */
|
||||
.ql-snow.ql-toolbar button:hover,
|
||||
.ql-snow.ql-toolbar button:focus,
|
||||
.ql-snow.ql-toolbar button.ql-active,
|
||||
.ql-snow.ql-toolbar .ql-picker-label:hover,
|
||||
.ql-snow.ql-toolbar .ql-picker-label.ql-active,
|
||||
.ql-snow.ql-toolbar .ql-picker-item:hover,
|
||||
.ql-snow.ql-toolbar .ql-picker-item.ql-selected,
|
||||
.ql-snow .ql-picker.ql-expanded .ql-picker-label {
|
||||
color: oklch(var(--p));
|
||||
}
|
||||
.ql-snow.ql-toolbar button:hover .ql-stroke,
|
||||
.ql-snow.ql-toolbar button:focus .ql-stroke,
|
||||
.ql-snow.ql-toolbar button.ql-active .ql-stroke,
|
||||
.ql-snow.ql-toolbar button:hover .ql-stroke-miter,
|
||||
.ql-snow.ql-toolbar button.ql-active .ql-stroke-miter,
|
||||
.ql-snow.ql-toolbar .ql-picker-label:hover .ql-stroke,
|
||||
.ql-snow.ql-toolbar .ql-picker-label.ql-active .ql-stroke,
|
||||
.ql-snow.ql-toolbar .ql-picker-item:hover .ql-stroke,
|
||||
.ql-snow.ql-toolbar .ql-picker-item.ql-selected .ql-stroke,
|
||||
.ql-snow .ql-picker.ql-expanded .ql-picker-label .ql-stroke {
|
||||
stroke: oklch(var(--p));
|
||||
}
|
||||
.ql-snow.ql-toolbar button:hover .ql-fill,
|
||||
.ql-snow.ql-toolbar button:focus .ql-fill,
|
||||
.ql-snow.ql-toolbar button.ql-active .ql-fill,
|
||||
.ql-snow.ql-toolbar button:hover .ql-stroke.ql-fill,
|
||||
.ql-snow.ql-toolbar button:focus .ql-stroke.ql-fill,
|
||||
.ql-snow.ql-toolbar button.ql-active .ql-stroke.ql-fill,
|
||||
.ql-snow.ql-toolbar .ql-picker-label:hover .ql-fill,
|
||||
.ql-snow.ql-toolbar .ql-picker-label.ql-active .ql-fill,
|
||||
.ql-snow.ql-toolbar .ql-picker-item:hover .ql-fill,
|
||||
.ql-snow.ql-toolbar .ql-picker-item.ql-selected .ql-fill {
|
||||
fill: oklch(var(--p));
|
||||
}
|
||||
/* link tooltip popup */
|
||||
.ql-snow .ql-tooltip {
|
||||
background-color: oklch(var(--b1));
|
||||
border-color: oklch(var(--b3));
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
|
||||
color: oklch(var(--bc));
|
||||
}
|
||||
.ql-snow .ql-tooltip input[type=text] {
|
||||
background: oklch(var(--b2));
|
||||
border-color: oklch(var(--b3));
|
||||
color: oklch(var(--bc));
|
||||
}
|
||||
.ql-snow .ql-tooltip a {
|
||||
color: oklch(var(--p));
|
||||
}
|
||||
.ql-snow .ql-tooltip a.ql-action::after {
|
||||
border-color: oklch(var(--b3));
|
||||
}
|
||||
.ql-snow .ql-editor a {
|
||||
color: oklch(var(--p));
|
||||
}
|
||||
.blog-image-size-controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
.blog-image-size-controls.hidden {
|
||||
display: none;
|
||||
}
|
||||
.blog-image-size-controls button {
|
||||
border: 1px solid oklch(var(--b3));
|
||||
background: oklch(var(--b2));
|
||||
padding: 0.3rem 0.65rem;
|
||||
line-height: 1;
|
||||
}
|
||||
.blog-image-size-controls button:hover {
|
||||
border-color: oklch(var(--p));
|
||||
color: oklch(var(--p));
|
||||
}
|
||||
.blog-image-size-controls label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.blog-image-size-controls input {
|
||||
width: 5rem;
|
||||
}
|
||||
.blog-editor img,
|
||||
.blog-content img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin: 1rem auto;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
.blog-editor img {
|
||||
cursor: pointer;
|
||||
}
|
||||
.blog-image-small {
|
||||
width: min(100%, 18rem);
|
||||
}
|
||||
.blog-image-medium {
|
||||
width: min(100%, 34rem);
|
||||
}
|
||||
.blog-image-full {
|
||||
width: 100%;
|
||||
}
|
||||
.blog-content {
|
||||
line-height: 1.75;
|
||||
}
|
||||
.blog-content h2 {
|
||||
margin: 1.5rem 0 0.75rem;
|
||||
font-size: 1.35rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.blog-content h3 {
|
||||
margin: 1.25rem 0 0.5rem;
|
||||
font-size: 1.15rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.blog-content p,
|
||||
.blog-content ul,
|
||||
.blog-content ol {
|
||||
margin: 0.75rem 0;
|
||||
}
|
||||
.blog-content ul {
|
||||
list-style: disc;
|
||||
padding-left: 1.4rem;
|
||||
}
|
||||
.blog-content ol {
|
||||
list-style: decimal;
|
||||
padding-left: 1.4rem;
|
||||
}
|
||||
.blog-content a {
|
||||
color: oklch(var(--p));
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* --- small screens ----------------------------------------- */
|
||||
@media (max-width: 767px) {
|
||||
.term-nav { gap: 0.5rem; }
|
||||
.term-title { font-size: 1.4rem; }
|
||||
}
|
||||
BIN
assets/static/favicon/android-chrome-192x192.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
assets/static/favicon/android-chrome-512x512.png
Normal file
|
After Width: | Height: | Size: 187 KiB |
BIN
assets/static/favicon/apple-touch-icon.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
assets/static/favicon/favicon-16x16.png
Normal file
|
After Width: | Height: | Size: 601 B |
BIN
assets/static/favicon/favicon-32x32.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/static/favicon/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
1
assets/static/favicon/site.webmanifest
Normal file
@@ -0,0 +1 @@
|
||||
{"name":"","short_name":"","icons":[{"src":"/static/favicon/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/static/favicon/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
|
||||
BIN
assets/static/image.png
Normal file
|
After Width: | Height: | Size: 298 KiB |
149
assets/static/js/blog-editor.js
Normal file
@@ -0,0 +1,149 @@
|
||||
(function () {
|
||||
function setImageSize(image, size) {
|
||||
image.classList.remove('blog-image-small', 'blog-image-medium', 'blog-image-full');
|
||||
image.style.removeProperty('width');
|
||||
image.style.removeProperty('height');
|
||||
image.classList.add('blog-image-' + size);
|
||||
}
|
||||
|
||||
function setImageWidth(image, width) {
|
||||
var px = parseInt(width, 10);
|
||||
if (!Number.isFinite(px) || px < 40) return;
|
||||
image.classList.remove('blog-image-small', 'blog-image-medium', 'blog-image-full');
|
||||
image.style.width = Math.min(px, 1200) + 'px';
|
||||
image.style.height = 'auto';
|
||||
}
|
||||
|
||||
function normalizeEditorImages(root) {
|
||||
root.querySelectorAll('img').forEach(function (image) {
|
||||
if (
|
||||
!image.classList.contains('blog-image-small')
|
||||
&& !image.classList.contains('blog-image-medium')
|
||||
&& !image.classList.contains('blog-image-full')
|
||||
) {
|
||||
image.classList.add('blog-image-full');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initEditor(form) {
|
||||
var editorEl = form.querySelector('[data-rich-editor]');
|
||||
var contentInput = form.querySelector('[data-rich-content]');
|
||||
var status = form.querySelector('[data-rich-status]');
|
||||
var imageControls = form.querySelector('[data-image-size-controls]');
|
||||
var imageWidthInput = form.querySelector('[data-image-width]');
|
||||
if (!editorEl || !contentInput || !window.Quill) return;
|
||||
|
||||
var selectedImage = null;
|
||||
var toolbar = [
|
||||
[{ header: [2, 3, false] }],
|
||||
['bold', 'italic'],
|
||||
[{ list: 'ordered' }, { list: 'bullet' }],
|
||||
['link', 'image'],
|
||||
['clean']
|
||||
];
|
||||
var editor = new Quill(editorEl, {
|
||||
modules: { toolbar: toolbar },
|
||||
placeholder: '',
|
||||
theme: 'snow'
|
||||
});
|
||||
var initialContent = contentInput.value.trim();
|
||||
if (initialContent) {
|
||||
if (initialContent.indexOf('<') >= 0) editor.clipboard.dangerouslyPasteHTML(initialContent);
|
||||
else editor.setText(initialContent);
|
||||
normalizeEditorImages(editor.root);
|
||||
}
|
||||
|
||||
function syncContent() {
|
||||
normalizeEditorImages(editor.root);
|
||||
contentInput.value = editor.root.innerHTML;
|
||||
}
|
||||
|
||||
function setStatus(message) {
|
||||
if (status) status.textContent = message || '';
|
||||
}
|
||||
|
||||
function chooseImageFile() {
|
||||
var input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'image/jpeg,image/png,image/webp,image/gif';
|
||||
input.addEventListener('change', function () {
|
||||
var file = input.files && input.files[0];
|
||||
if (!file) return;
|
||||
uploadImage(file);
|
||||
});
|
||||
input.click();
|
||||
}
|
||||
|
||||
async function uploadImage(file) {
|
||||
var formData = new FormData();
|
||||
formData.append('file', file);
|
||||
setStatus(status ? status.dataset.uploading : '');
|
||||
try {
|
||||
var response = await fetch('/images/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
credentials: 'same-origin'
|
||||
});
|
||||
if (!response.ok) throw new Error('upload failed');
|
||||
var result = await response.json();
|
||||
var range = editor.getSelection(true);
|
||||
editor.insertEmbed(range.index, 'image', result.url, 'user');
|
||||
editor.setSelection(range.index + 1, 0, 'silent');
|
||||
window.setTimeout(function () {
|
||||
var images = editor.root.querySelectorAll('img');
|
||||
var image = images[images.length - 1];
|
||||
if (image) {
|
||||
setImageSize(image, 'full');
|
||||
selectedImage = image;
|
||||
if (imageControls) imageControls.classList.remove('hidden');
|
||||
}
|
||||
syncContent();
|
||||
}, 0);
|
||||
setStatus(status ? status.dataset.uploaded : '');
|
||||
} catch (_error) {
|
||||
setStatus(status ? status.dataset.error : '');
|
||||
}
|
||||
}
|
||||
|
||||
editor.getModule('toolbar').addHandler('image', chooseImageFile);
|
||||
|
||||
editor.root.addEventListener('click', function (event) {
|
||||
if (event.target && event.target.tagName === 'IMG') {
|
||||
selectedImage = event.target;
|
||||
if (imageWidthInput) imageWidthInput.value = parseInt(selectedImage.style.width, 10) || '';
|
||||
if (imageControls) imageControls.classList.remove('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
if (imageControls) {
|
||||
imageControls.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('[data-image-size]');
|
||||
if (button && selectedImage) {
|
||||
setImageSize(selectedImage, button.dataset.imageSize);
|
||||
if (imageWidthInput) imageWidthInput.value = '';
|
||||
syncContent();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (imageWidthInput) {
|
||||
imageWidthInput.addEventListener('change', function () {
|
||||
if (!selectedImage) return;
|
||||
setImageWidth(selectedImage, imageWidthInput.value);
|
||||
syncContent();
|
||||
});
|
||||
}
|
||||
|
||||
editor.on('text-change', syncContent);
|
||||
form.addEventListener('submit', syncContent);
|
||||
syncContent();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.querySelectorAll('[data-rich-editor]').forEach(function (editorEl) {
|
||||
var form = editorEl.closest('form');
|
||||
if (form) initEditor(form);
|
||||
});
|
||||
});
|
||||
})();
|
||||
1
assets/static/vendor/htmx/htmx-1.9.12.min.js
vendored
Normal file
31
assets/static/vendor/quill/LICENSE
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
Copyright (c) 2017-2024, Slab
|
||||
Copyright (c) 2014, Jason Chen
|
||||
Copyright (c) 2013, salesforce.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
3
assets/static/vendor/quill/quill.js
vendored
Normal file
7
assets/static/vendor/quill/quill.js.LICENSE.txt
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/*!
|
||||
* Quill Editor v2.0.3
|
||||
* https://quilljs.com
|
||||
* Copyright (c) 2017-2024, Slab
|
||||
* Copyright (c) 2014, Jason Chen
|
||||
* Copyright (c) 2013, salesforce.com
|
||||
*/
|
||||
10
assets/static/vendor/quill/quill.snow.css
vendored
Normal file
36
assets/views/admin/about.html
Normal file
@@ -0,0 +1,36 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="edit-about", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<div class="space-y-2">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold">{{ t(key="edit-about", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="text-sm opacity-70">{{ t(key="update-about-page", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<a href="/about" class="btn btn-ghost btn-sm">{{ t(key="view-page", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
|
||||
<div class="card border border-base-300 bg-base-100 shadow-sm">
|
||||
<div class="card-body">
|
||||
<form method="post" action="/admin/about" class="space-y-2">
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text">{{ t(key="title", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="text" name="title" value="{{ page.title }}" required class="input input-bordered w-full">
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text">{{ t(key="content", lang=lang | default(value='sk')) }}</span></label>
|
||||
<textarea name="content" rows="16" required class="textarea textarea-bordered w-full">{{ page.content }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-2 pt-2">
|
||||
<button type="submit" class="btn btn-neutral btn-sm">{{ t(key="save", lang=lang | default(value='sk')) }}</button>
|
||||
<a href="/admin/dashboard" class="btn btn-ghost btn-sm">{{ t(key="cancel", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
81
assets/views/admin/audio/albums.html
Normal file
@@ -0,0 +1,81 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="albums-title", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}audio/albums{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="albums-title", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">{{ t(key="admin-albums-desc", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/admin/audio/albums/create" class="btn btn-primary btn-sm">{{ t(key="new-album", lang=lang | default(value='sk')) }}</a>
|
||||
<a href="/admin/audio/tracks" class="btn btn-outline btn-sm">{{ t(key="songs-title", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="term-note">
|
||||
<p class="term-note-title">{{ t(key="admin-albums-before", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="term-step">
|
||||
<span class="term-step-n">[1]</span>
|
||||
<span>{{ t(key="admin-albums-step-upload", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="term-step">
|
||||
<span class="term-step-n">[2]</span>
|
||||
<span>{{ t(key="admin-albums-step-create", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/albums/</span>
|
||||
<span class="term-head-meta term-tag is-purple">{{ albums | length }} {{ t(key="albums-title", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if albums | length > 0 %}
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t(key="album", lang=lang | default(value='sk')) }}</th>
|
||||
<th>{{ t(key="status", lang=lang | default(value='sk')) }}</th>
|
||||
<th>{{ t(key="songs-title", lang=lang | default(value='sk')) }}</th>
|
||||
<th class="text-right">{{ t(key="actions", lang=lang | default(value='sk')) }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in albums %}
|
||||
<tr>
|
||||
<td class="font-medium">{{ row.album.title }}</td>
|
||||
<td>
|
||||
{% if row.album.published %}
|
||||
<span class="term-tag is-green">{{ t(key="published", lang=lang | default(value='sk')) }}</span>
|
||||
{% else %}
|
||||
<span class="term-tag">{{ t(key="draft", lang=lang | default(value='sk')) }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ row.track_count }}</td>
|
||||
<td>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<a href="/admin/audio/albums/{{ row.album.id }}/tracks" class="btn btn-primary btn-sm">{{ t(key="open-edit", lang=lang | default(value='sk')) }}</a>
|
||||
<a href="/audio/albums/{{ row.album.slug }}" class="btn btn-ghost btn-sm">{{ t(key="view", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="term-empty">
|
||||
<p class="font-medium">{{ t(key="admin-no-albums", lang=lang | default(value='sk')) }}</p>
|
||||
<p class="term-empty-cmd">{{ t(key="admin-create-album-empty", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="pt-2">
|
||||
<a href="/admin/audio/albums/create" class="btn btn-primary btn-sm">{{ t(key="new-album", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
93
assets/views/admin/audio/new_album.html
Normal file
@@ -0,0 +1,93 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="new-album", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}audio/new-album{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="new-album", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">{{ t(key="admin-new-album-desc", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/admin/audio/albums" class="btn btn-outline btn-sm">{{ t(key="cancel", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/albums/new</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="post" action="/admin/audio/albums/create" enctype="multipart/form-data" class="space-y-2">
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">{{ t(key="album-title-label", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="text" name="title" required class="input input-bordered w-full">
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">{{ t(key="artist", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="text" name="artist" class="input input-bordered w-full">
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">{{ t(key="release-date", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="date" name="release_date" class="input input-bordered w-full">
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">{{ t(key="cover-image", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="file" name="cover" accept="image/png,image/jpeg,image/webp,image/gif" class="file-input file-input-bordered w-full">
|
||||
<p class="term-help">{{ t(key="cover-help", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">{{ t(key="description", lang=lang | default(value='sk')) }}</span></label>
|
||||
<textarea name="description" rows="5" class="textarea textarea-bordered w-full"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="term-formdiv"></div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">{{ t(key="songs-in-album", lang=lang | default(value='sk')) }}</span></label>
|
||||
{% if available_tracks | length > 0 %}
|
||||
<div class="term-picklist">
|
||||
{% for song in available_tracks %}
|
||||
<label class="term-pick">
|
||||
<input type="checkbox" name="track_ids" value="{{ song.id }}" class="checkbox checkbox-sm">
|
||||
<span class="min-w-0 flex-1 font-medium">{{ song.title }}</span>
|
||||
{% if song.published %}
|
||||
<span class="term-tag is-green">{{ t(key="published", lang=lang | default(value='sk')) }}</span>
|
||||
{% else %}
|
||||
<span class="term-tag">{{ t(key="draft", lang=lang | default(value='sk')) }}</span>
|
||||
{% endif %}
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<p class="term-help">{{ t(key="free-songs-help", lang=lang | default(value='sk')) }}</p>
|
||||
{% else %}
|
||||
<div class="term-picklist">
|
||||
<div class="term-pick">
|
||||
<span class="term-help" style="margin:0">
|
||||
{{ t(key="no-free-songs", lang=lang | default(value='sk')) }}
|
||||
<a href="/admin/audio/tracks/upload" class="t-blue">{{ t(key="upload-song-first", lang=lang | default(value='sk')) }}</a>,
|
||||
{{ t(key="create-empty-add-later", lang=lang | default(value='sk')) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<label class="label cursor-pointer justify-start gap-2">
|
||||
<input type="checkbox" name="published" class="checkbox checkbox-sm">
|
||||
<span class="label-text">{{ t(key="publish-album-now", lang=lang | default(value='sk')) }}</span>
|
||||
</label>
|
||||
|
||||
<div class="flex flex-wrap gap-2 pt-2">
|
||||
<button type="submit" class="btn btn-primary btn-sm">{{ t(key="create-album", lang=lang | default(value='sk')) }}</button>
|
||||
<a href="/admin/audio/albums" class="btn btn-ghost btn-sm">{{ t(key="cancel", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
99
assets/views/admin/audio/songs.html
Normal file
@@ -0,0 +1,99 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="songs-title-admin", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}audio/songs{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="songs-title-admin", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">{{ t(key="admin-songs-desc", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/admin/audio/tracks/upload" class="btn btn-primary btn-sm">{{ t(key="upload-song", lang=lang | default(value='sk')) }}</a>
|
||||
<a href="/admin/audio/albums" class="btn btn-outline btn-sm">{{ t(key="albums-title", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="term-note">
|
||||
<p class="term-note-title">{{ t(key="admin-audio-how", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="term-step">
|
||||
<span class="term-step-n">[1]</span>
|
||||
<span>{{ t(key="admin-audio-step-upload", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="term-step">
|
||||
<span class="term-step-n">[2]</span>
|
||||
<span>{{ t(key="admin-audio-step-album", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<p class="term-note-foot">{{ t(key="admin-audio-note", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/songs/</span>
|
||||
<span class="term-head-meta term-tag is-green">{{ tracks | length }} {{ t(key="songs-title", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if tracks | length > 0 %}
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t(key="song", lang=lang | default(value='sk')) }}</th>
|
||||
<th>{{ t(key="where", lang=lang | default(value='sk')) }}</th>
|
||||
<th>{{ t(key="status", lang=lang | default(value='sk')) }}</th>
|
||||
<th class="text-right">{{ t(key="actions", lang=lang | default(value='sk')) }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for track in tracks %}
|
||||
<tr>
|
||||
<td class="font-medium">{{ track.title }}</td>
|
||||
<td>
|
||||
{% if track.album_id %}
|
||||
<span class="term-tag is-purple">{{ t(key="in-album", lang=lang | default(value='sk')) }}</span>
|
||||
{% else %}
|
||||
<span class="term-tag is-blue">{{ t(key="single", lang=lang | default(value='sk')) }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if track.published %}
|
||||
<span class="term-tag is-green">{{ t(key="published", lang=lang | default(value='sk')) }}</span>
|
||||
{% else %}
|
||||
<span class="term-tag">{{ t(key="draft", lang=lang | default(value='sk')) }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<a href="/audio/tracks/{{ track.id }}/stream" class="btn btn-ghost btn-sm">{{ t(key="play", lang=lang | default(value='sk')) }}</a>
|
||||
{% if track.published %}
|
||||
<form method="post" action="/admin/audio/tracks/{{ track.id }}/unpublish">
|
||||
<button type="submit" class="btn btn-ghost btn-sm">{{ t(key="unpublish", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form method="post" action="/admin/audio/tracks/{{ track.id }}/publish">
|
||||
<button type="submit" class="btn btn-ghost btn-sm t-green">{{ t(key="publish", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
<form method="post" action="/admin/audio/tracks/{{ track.id }}/delete">
|
||||
<button type="submit" class="btn btn-ghost btn-sm t-red">{{ t(key="delete", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="term-empty">
|
||||
<p class="font-medium">{{ t(key="admin-no-songs", lang=lang | default(value='sk')) }}</p>
|
||||
<p class="term-empty-cmd">{{ t(key="admin-upload-first-song", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="pt-2">
|
||||
<a href="/admin/audio/tracks/upload" class="btn btn-primary btn-sm">{{ t(key="upload-song", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
123
assets/views/admin/audio/tracks.html
Normal file
@@ -0,0 +1,123 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ album.title }} - {{ t(key="admin-tracklist", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}audio/{{ album.slug }}{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ album.title }}</h1>
|
||||
<p class="term-sub">
|
||||
{{ t(key="album", lang=lang | default(value='sk')) }} · {{ tracks | length }} {{ t(key="songs-title", lang=lang | default(value='sk')) }} ·
|
||||
{% if album.published %}<span class="t-green">{{ t(key="published", lang=lang | default(value='sk')) }}</span>{% else %}<span class="t-yellow">{{ t(key="draft", lang=lang | default(value='sk')) }}</span>{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/admin/audio/albums/{{ album.id }}/tracks/upload" class="btn btn-primary btn-sm">{{ t(key="upload-song-into-album", lang=lang | default(value='sk')) }}</a>
|
||||
<a href="/audio/albums/{{ album.slug }}" class="btn btn-outline btn-sm">{{ t(key="view", lang=lang | default(value='sk')) }}</a>
|
||||
<a href="/admin/audio/albums" class="btn btn-outline btn-sm">{{ t(key="albums-title", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="term-note">
|
||||
<p class="term-note-title">{{ t(key="admin-two-ways-title", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="term-step">
|
||||
<span class="term-step-n">[a]</span>
|
||||
<span>{{ t(key="admin-two-ways-upload", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="term-step">
|
||||
<span class="term-step-n">[b]</span>
|
||||
<span>{{ t(key="admin-two-ways-pick", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ album.slug }}/tracklist</span>
|
||||
<span class="term-head-meta term-tag is-purple">{{ tracks | length }} {{ t(key="songs-title", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if available_tracks | length > 0 %}
|
||||
<form method="post" action="/admin/audio/albums/{{ album.id }}/tracks/add" class="space-y-2">
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">{{ t(key="admin-add-existing-song", lang=lang | default(value='sk')) }}</span></label>
|
||||
<select name="track_id" required class="select select-bordered w-full">
|
||||
{% for song in available_tracks %}
|
||||
<option value="{{ song.id }}">{{ song.title }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<p class="term-help">{{ t(key="admin-existing-song-help", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-outline btn-sm">{{ t(key="admin-add-to-album", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
<div class="term-formdiv"></div>
|
||||
{% endif %}
|
||||
|
||||
{% if tracks | length > 0 %}
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>{{ t(key="song", lang=lang | default(value='sk')) }}</th>
|
||||
<th>{{ t(key="status", lang=lang | default(value='sk')) }}</th>
|
||||
<th>{{ t(key="featured", lang=lang | default(value='sk')) }}</th>
|
||||
<th class="text-right">{{ t(key="actions", lang=lang | default(value='sk')) }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for track in tracks %}
|
||||
<tr>
|
||||
<td class="t-dim">{% if track.track_number %}{{ track.track_number }}{% else %}—{% endif %}</td>
|
||||
<td class="font-medium">{{ track.title }}</td>
|
||||
<td>
|
||||
{% if track.published %}
|
||||
<span class="term-tag is-green">{{ t(key="published", lang=lang | default(value='sk')) }}</span>
|
||||
{% else %}
|
||||
<span class="term-tag">{{ t(key="draft", lang=lang | default(value='sk')) }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if track.featured %}
|
||||
<span class="term-tag is-aqua">{{ t(key="featured", lang=lang | default(value='sk')) }}</span>
|
||||
{% else %}
|
||||
<span class="t-dim">—</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<a href="/audio/tracks/{{ track.id }}/stream" class="btn btn-ghost btn-sm">{{ t(key="play", lang=lang | default(value='sk')) }}</a>
|
||||
{% if track.published %}
|
||||
<form method="post" action="/admin/audio/tracks/{{ track.id }}/unpublish">
|
||||
<button type="submit" class="btn btn-ghost btn-sm">{{ t(key="unpublish", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form method="post" action="/admin/audio/tracks/{{ track.id }}/publish">
|
||||
<button type="submit" class="btn btn-ghost btn-sm t-green">{{ t(key="publish", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
<form method="post" action="/admin/audio/tracks/{{ track.id }}/remove-from-album">
|
||||
<button type="submit" class="btn btn-ghost btn-sm">{{ t(key="remove-from-album", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
<form method="post" action="/admin/audio/tracks/{{ track.id }}/delete">
|
||||
<button type="submit" class="btn btn-ghost btn-sm t-red">{{ t(key="delete", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="term-empty">
|
||||
<p class="font-medium">{{ t(key="admin-album-empty", lang=lang | default(value='sk')) }}</p>
|
||||
<p class="term-empty-cmd">{{ t(key="admin-album-empty-help", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="pt-2">
|
||||
<a href="/admin/audio/albums/{{ album.id }}/tracks/upload" class="btn btn-primary btn-sm">{{ t(key="upload-song-into-album", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
76
assets/views/admin/audio/upload_track.html
Normal file
@@ -0,0 +1,76 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="upload-song-title", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}audio/upload{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="upload-song-title", lang=lang | default(value='sk')) }}</h1>
|
||||
{% if album %}
|
||||
<p class="term-sub">{{ t(key="upload-into-album-help", lang=lang | default(value='sk')) }} "{{ album.title }}".</p>
|
||||
{% else %}
|
||||
<p class="term-sub">{{ t(key="upload-single-help", lang=lang | default(value='sk')) }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
{% if album %}
|
||||
<a href="/admin/audio/albums/{{ album.id }}/tracks" class="btn btn-outline btn-sm">{{ t(key="cancel", lang=lang | default(value='sk')) }}</a>
|
||||
{% else %}
|
||||
<a href="/admin/audio/tracks" class="btn btn-outline btn-sm">{{ t(key="cancel", lang=lang | default(value='sk')) }}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">{% if album %}~/audio/{{ album.slug }}/upload{% else %}~/audio/songs/upload{% endif %}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if album %}
|
||||
<form method="post" action="/admin/audio/albums/{{ album.id }}/tracks/upload-file" enctype="multipart/form-data" class="space-y-2">
|
||||
{% else %}
|
||||
<form method="post" action="/admin/audio/tracks/upload-file" enctype="multipart/form-data" class="space-y-2">
|
||||
{% endif %}
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">1. {{ t(key="audio-file", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="file" name="file" accept="audio/mpeg,audio/wav,audio/ogg,audio/flac,audio/aac,audio/mp4,audio/webm" required class="file-input file-input-bordered w-full">
|
||||
<p class="term-help">{{ t(key="audio-file-help", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">2. {{ t(key="title", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="text" name="title" class="input input-bordered w-full">
|
||||
<p class="term-help">{{ t(key="title-help", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
|
||||
{% if album %}
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">3. {{ t(key="track-number", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="number" name="track_number" min="1" class="input input-bordered w-full" placeholder="1">
|
||||
<p class="term-help">{{ t(key="track-number-help", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<label class="label cursor-pointer justify-start gap-2">
|
||||
<input type="checkbox" name="featured" class="checkbox checkbox-sm">
|
||||
<span class="label-text">{{ t(key="featured-help", lang=lang | default(value='sk')) }}</span>
|
||||
</label>
|
||||
|
||||
<label class="label cursor-pointer justify-start gap-2">
|
||||
<input type="checkbox" name="published" class="checkbox checkbox-sm">
|
||||
<span class="label-text">{{ t(key="publish-song-now", lang=lang | default(value='sk')) }}</span>
|
||||
</label>
|
||||
|
||||
<div class="flex flex-wrap gap-2 pt-2">
|
||||
<button type="submit" class="btn btn-primary btn-sm">{{ t(key="upload-song", lang=lang | default(value='sk')) }}</button>
|
||||
{% if album %}
|
||||
<a href="/admin/audio/albums/{{ album.id }}/tracks" class="btn btn-ghost btn-sm">{{ t(key="cancel", lang=lang | default(value='sk')) }}</a>
|
||||
{% else %}
|
||||
<a href="/admin/audio/tracks" class="btn btn-ghost btn-sm">{{ t(key="cancel", lang=lang | default(value='sk')) }}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
154
assets/views/admin/base.html
Normal file
@@ -0,0 +1,154 @@
|
||||
<!doctype html>
|
||||
<html lang="{{ lang | default(value='sk') }}" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}{{ t(key="admin-title", lang=lang | default(value='sk')) }}{% endblock title %}</title>
|
||||
<meta name="description" content="{% block meta_description %}{{ t(key="meta-description", lang=lang | default(value='sk')) }}{% endblock meta_description %}">
|
||||
<link rel="icon" type="image/x-icon" href="/static/favicon/favicon.ico">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon/favicon-16x16.png">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon.png">
|
||||
<link rel="manifest" href="/static/favicon/site.webmanifest">
|
||||
<script>
|
||||
function applyTheme(t) {
|
||||
var dark = t === 'dark'
|
||||
|| (t === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
document.documentElement.setAttribute('data-theme', dark ? 'dark' : 'light');
|
||||
}
|
||||
function highlightTheme(t) {
|
||||
document.querySelectorAll('[data-theme-opt]').forEach(function (b) {
|
||||
var on = b.getAttribute('data-theme-opt') === t;
|
||||
b.classList.toggle('active', on);
|
||||
var chk = b.querySelector('.opt-check');
|
||||
if (chk) chk.classList.toggle('hidden', !on);
|
||||
});
|
||||
}
|
||||
function setTheme(t) {
|
||||
localStorage.setItem('theme', t);
|
||||
applyTheme(t);
|
||||
highlightTheme(t);
|
||||
}
|
||||
applyTheme(localStorage.getItem('theme') || 'dark');
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function () {
|
||||
if ((localStorage.getItem('theme') || 'dark') === 'system') applyTheme('system');
|
||||
});
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
highlightTheme(localStorage.getItem('theme') || 'dark');
|
||||
var path = location.pathname;
|
||||
document.querySelectorAll('.term-navlinks a[data-nav]').forEach(function (a) {
|
||||
var h = a.getAttribute('data-nav');
|
||||
if (h === path || (h !== '/' && path.indexOf(h) === 0)) a.classList.add('is-active');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<link href="/static/css/app.css?v=2026-05-20b" rel="stylesheet" type="text/css">
|
||||
{% block head %}{% endblock head %}
|
||||
<link href="/static/css/theme.css?v=2026-05-20b" rel="stylesheet" type="text/css">
|
||||
<script src="/static/vendor/htmx/htmx-1.9.12.min.js"></script>
|
||||
<style>
|
||||
@media (min-width: 768px) {
|
||||
.nav-menu { flex-direction: row; }
|
||||
}
|
||||
#nav-backdrop { display: none; }
|
||||
@media (max-width: 767px) {
|
||||
#nav-backdrop {
|
||||
display: block;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 40;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 0.15s ease, visibility 0s linear 0.2s;
|
||||
}
|
||||
.term-titlebar:has(.dropdown:focus-within) ~ #nav-backdrop {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
transition: opacity 0.15s ease, visibility 0s;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="flex min-h-screen flex-col bg-base-100 text-base-content antialiased">
|
||||
<header class="term-titlebar">
|
||||
<nav class="term-nav">
|
||||
<a href="/admin/dashboard" class="term-brand">{{ t(key="admin-title", lang=lang | default(value='sk')) }}</a>
|
||||
<ul class="nav-menu term-navlinks menu menu-sm hidden items-center md:flex">
|
||||
<li><a href="/admin/dashboard" data-nav="/admin/dashboard">{{ t(key="admin-dashboard", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/admin/blog/articles" data-nav="/admin/blog">{{ t(key="admin-blog", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/admin/audio/albums" data-nav="/admin/audio">{{ t(key="admin-audio", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/admin/about" data-nav="/admin/about">{{ t(key="admin-about", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/" class="t-blue">{{ t(key="admin-exit", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li>
|
||||
<form method="post" action="/admin/logout">
|
||||
<button type="submit" class="t-red w-full">{{ t(key="logout", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="term-nav-right">
|
||||
<div class="dropdown dropdown-end md:hidden">
|
||||
<div tabindex="0" role="button" class="btn btn-ghost btn-sm btn-circle" aria-label="{{ t(key='menu', lang=lang | default(value='sk')) }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||
stroke="currentColor" class="h-5 w-5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
|
||||
</svg>
|
||||
</div>
|
||||
<ul tabindex="0"
|
||||
class="menu dropdown-content z-50 mt-3 w-52 border border-base-300 bg-base-200 p-2 shadow-lg">
|
||||
<li><a href="/admin/dashboard">{{ t(key="admin-dashboard", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/admin/blog/articles">{{ t(key="admin-blog", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/admin/audio/albums">{{ t(key="admin-audio", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/admin/about">{{ t(key="admin-about", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/" class="t-blue">{{ t(key="admin-exit", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li>
|
||||
<form method="post" action="/admin/logout">
|
||||
<button type="submit" class="t-red w-full">{{ t(key="logout", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="dropdown dropdown-end">
|
||||
<div tabindex="0" role="button" class="btn btn-ghost btn-sm btn-circle" aria-label="{{ t(key='settings', lang=lang | default(value='sk')) }}" title="{{ t(key='settings', lang=lang | default(value='sk')) }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||
stroke="currentColor" class="h-5 w-5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round"
|
||||
d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
|
||||
</svg>
|
||||
</div>
|
||||
<form method="post" action="/lang" hx-boost="false">
|
||||
<ul tabindex="0" class="menu dropdown-content z-50 mt-3 w-56 border border-base-300 bg-base-200 p-2 shadow-lg">
|
||||
<li class="menu-title">{{ t(key="settings-language", lang=lang | default(value='sk')) }}</li>
|
||||
<li>
|
||||
<button type="submit" name="lang" value="en" class="{% if lang | default(value='sk') == 'en' %}active{% endif %}">
|
||||
{{ t(key="language-en", lang=lang | default(value='sk')) }}
|
||||
{% if lang | default(value='sk') == 'en' %}
|
||||
<span class="ml-auto">✓</span>
|
||||
{% endif %}
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button type="submit" name="lang" value="sk" class="{% if lang | default(value='sk') == 'sk' %}active{% endif %}">
|
||||
{{ t(key="language-sk", lang=lang | default(value='sk')) }}
|
||||
{% if lang | default(value='sk') == 'sk' %}
|
||||
<span class="ml-auto">✓</span>
|
||||
{% endif %}
|
||||
</button>
|
||||
</li>
|
||||
<li class="menu-title">{{ t(key="settings-theme", lang=lang | default(value='sk')) }}</li>
|
||||
<li><button type="button" data-theme-opt="system" onclick="setTheme('system')">{{ t(key="theme-system", lang=lang | default(value='sk')) }} <span class="opt-check ml-auto hidden">✓</span></button></li>
|
||||
<li><button type="button" data-theme-opt="light" onclick="setTheme('light')">{{ t(key="theme-light", lang=lang | default(value='sk')) }} <span class="opt-check ml-auto hidden">✓</span></button></li>
|
||||
<li><button type="button" data-theme-opt="dark" onclick="setTheme('dark')">{{ t(key="theme-dark", lang=lang | default(value='sk')) }} <span class="opt-check ml-auto hidden">✓</span></button></li>
|
||||
</ul>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div id="nav-backdrop" aria-hidden="true"></div>
|
||||
<main class="term-main">
|
||||
{% block content %}{% endblock content %}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
63
assets/views/admin/blog/edit.html
Normal file
@@ -0,0 +1,63 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="edit-article", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block head %}
|
||||
<link href="/static/vendor/quill/quill.snow.css" rel="stylesheet" type="text/css">
|
||||
{% endblock head %}
|
||||
|
||||
{% block content %}
|
||||
<div class="space-y-2">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold">{{ t(key="edit-article", lang=lang | default(value='sk')) }}</h1>
|
||||
</div>
|
||||
<a href="/admin/blog/articles" class="btn btn-ghost btn-sm">{{ t(key="back-to-articles", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
|
||||
<div class="card border border-base-300 bg-base-100 shadow-sm">
|
||||
<div class="card-body">
|
||||
<form method="post" action="/admin/blog/articles/{{ article.id }}" class="space-y-2">
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text">{{ t(key="title", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="text" name="title" value="{{ article.title }}" required class="input input-bordered w-full">
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text">{{ t(key="excerpt", lang=lang | default(value='sk')) }}</span></label>
|
||||
<textarea name="excerpt" rows="4" class="textarea textarea-bordered w-full">{% if article.excerpt %}{{ article.excerpt }}{% endif %}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text">{{ t(key="content", lang=lang | default(value='sk')) }}</span></label>
|
||||
<textarea name="content" data-rich-content class="hidden">{{ article.content }}</textarea>
|
||||
<input type="hidden" name="featured_image_id" data-featured-image-id value="{% if article.featured_image_id %}{{ article.featured_image_id }}{% endif %}">
|
||||
<div data-rich-editor class="blog-editor"></div>
|
||||
<div data-image-size-controls class="blog-image-size-controls hidden">
|
||||
<span>{{ t(key="image-size", lang=lang | default(value='sk')) }}</span>
|
||||
<button type="button" data-image-size="small">{{ t(key="image-size-small", lang=lang | default(value='sk')) }}</button>
|
||||
<button type="button" data-image-size="medium">{{ t(key="image-size-medium", lang=lang | default(value='sk')) }}</button>
|
||||
<button type="button" data-image-size="full">{{ t(key="image-size-full", lang=lang | default(value='sk')) }}</button>
|
||||
<label>
|
||||
<span>{{ t(key="image-width-px", lang=lang | default(value='sk')) }}</span>
|
||||
<input type="number" min="40" max="1200" step="10" data-image-width class="input input-bordered input-sm">
|
||||
</label>
|
||||
</div>
|
||||
<p class="text-sm opacity-70" data-rich-status data-uploading='{{ t(key="image-uploading", lang=lang | default(value='sk')) }}' data-uploaded='{{ t(key="image-uploaded", lang=lang | default(value='sk')) }}' data-error='{{ t(key="image-upload-error", lang=lang | default(value='sk')) }}'></p>
|
||||
</div>
|
||||
|
||||
<label class="label cursor-pointer justify-start gap-2">
|
||||
<input type="checkbox" name="published" class="checkbox checkbox-sm" {% if article.published %}checked{% endif %}>
|
||||
<span class="label-text">{{ t(key="published", lang=lang | default(value='sk')) }}</span>
|
||||
</label>
|
||||
|
||||
<div class="flex flex-wrap gap-2 pt-2">
|
||||
<button type="submit" class="btn btn-neutral btn-sm">{{ t(key="save", lang=lang | default(value='sk')) }}</button>
|
||||
<a href="/admin/blog/articles" class="btn btn-ghost btn-sm">{{ t(key="cancel", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/vendor/quill/quill.js"></script>
|
||||
<script src="/static/js/blog-editor.js"></script>
|
||||
{% endblock content %}
|
||||
63
assets/views/admin/blog/index.html
Normal file
@@ -0,0 +1,63 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="admin-blog-articles", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<div class="space-y-2">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold">{{ t(key="admin-blog-articles", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="text-sm opacity-70">{{ t(key="admin-blog-index-desc", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<a href="/admin/blog/articles/new" class="btn btn-neutral btn-sm">{{ t(key="new-article", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
|
||||
<div class="card border border-base-300 bg-base-100 shadow-sm">
|
||||
<div class="card-body">
|
||||
{% if articles | length > 0 %}
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t(key="title", lang=lang | default(value='sk')) }}</th>
|
||||
<th>{{ t(key="status", lang=lang | default(value='sk')) }}</th>
|
||||
<th class="text-right">{{ t(key="actions", lang=lang | default(value='sk')) }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for article in articles %}
|
||||
<tr>
|
||||
<td class="font-medium">{{ article.title }}</td>
|
||||
<td>
|
||||
{% if article.published %}
|
||||
<span class="badge">{{ t(key="published", lang=lang | default(value='sk')) }}</span>
|
||||
{% else %}
|
||||
<span class="badge opacity-70">{{ t(key="draft", lang=lang | default(value='sk')) }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<div class="flex gap-2">
|
||||
<a href="/admin/blog/articles/{{ article.id }}/edit" class="btn btn-ghost btn-sm">{{ t(key="edit", lang=lang | default(value='sk')) }}</a>
|
||||
<form method="post" action="/admin/blog/articles/{{ article.id }}/delete">
|
||||
<button type="submit" class="btn btn-ghost btn-sm">{{ t(key="delete", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="text-center">
|
||||
<p class="font-medium">{{ t(key="admin-no-articles", lang=lang | default(value='sk')) }}</p>
|
||||
<p class="text-sm opacity-70">{{ t(key="admin-create-first-post", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="pt-2">
|
||||
<a href="/admin/blog/articles/new" class="btn btn-neutral btn-sm">{{ t(key="new-article", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
64
assets/views/admin/blog/new.html
Normal file
@@ -0,0 +1,64 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="new-article", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block head %}
|
||||
<link href="/static/vendor/quill/quill.snow.css" rel="stylesheet" type="text/css">
|
||||
{% endblock head %}
|
||||
|
||||
{% block content %}
|
||||
<div class="space-y-2">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold">{{ t(key="new-article", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="text-sm opacity-70">{{ t(key="admin-blog-create-desc", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<a href="/admin/blog/articles" class="btn btn-ghost btn-sm">{{ t(key="back-to-articles", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
|
||||
<div class="card border border-base-300 bg-base-100 shadow-sm">
|
||||
<div class="card-body">
|
||||
<form method="post" action="/admin/blog/articles" class="space-y-2">
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text">{{ t(key="title", lang=lang | default(value='sk')) }}</span></label>
|
||||
<input type="text" name="title" required class="input input-bordered w-full">
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text">{{ t(key="excerpt", lang=lang | default(value='sk')) }}</span></label>
|
||||
<textarea name="excerpt" rows="4" class="textarea textarea-bordered w-full"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text">{{ t(key="content", lang=lang | default(value='sk')) }}</span></label>
|
||||
<textarea name="content" data-rich-content class="hidden"></textarea>
|
||||
<input type="hidden" name="featured_image_id" data-featured-image-id>
|
||||
<div data-rich-editor class="blog-editor"></div>
|
||||
<div data-image-size-controls class="blog-image-size-controls hidden">
|
||||
<span>{{ t(key="image-size", lang=lang | default(value='sk')) }}</span>
|
||||
<button type="button" data-image-size="small">{{ t(key="image-size-small", lang=lang | default(value='sk')) }}</button>
|
||||
<button type="button" data-image-size="medium">{{ t(key="image-size-medium", lang=lang | default(value='sk')) }}</button>
|
||||
<button type="button" data-image-size="full">{{ t(key="image-size-full", lang=lang | default(value='sk')) }}</button>
|
||||
<label>
|
||||
<span>{{ t(key="image-width-px", lang=lang | default(value='sk')) }}</span>
|
||||
<input type="number" min="40" max="1200" step="10" data-image-width class="input input-bordered input-sm">
|
||||
</label>
|
||||
</div>
|
||||
<p class="text-sm opacity-70" data-rich-status data-uploading='{{ t(key="image-uploading", lang=lang | default(value='sk')) }}' data-uploaded='{{ t(key="image-uploaded", lang=lang | default(value='sk')) }}' data-error='{{ t(key="image-upload-error", lang=lang | default(value='sk')) }}'></p>
|
||||
</div>
|
||||
|
||||
<label class="label cursor-pointer justify-start gap-2">
|
||||
<input type="checkbox" name="published" class="checkbox checkbox-sm">
|
||||
<span class="label-text">{{ t(key="published", lang=lang | default(value='sk')) }}</span>
|
||||
</label>
|
||||
|
||||
<div class="flex flex-wrap gap-2 pt-2">
|
||||
<button type="submit" class="btn btn-neutral btn-sm">{{ t(key="create", lang=lang | default(value='sk')) }}</button>
|
||||
<a href="/admin/blog/articles" class="btn btn-ghost btn-sm">{{ t(key="cancel", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/vendor/quill/quill.js"></script>
|
||||
<script src="/static/js/blog-editor.js"></script>
|
||||
{% endblock content %}
|
||||
60
assets/views/admin/index.html
Normal file
@@ -0,0 +1,60 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="admin-title", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}dashboard{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="admin-dashboard", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">{{ t(key="admin-session", lang=lang | default(value='sk')) }}: {{ admin.email }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/" class="btn btn-outline btn-sm">[ {{ t(key="view-site", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="term-grid">
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">/admin/blog</span>
|
||||
<span class="term-head-meta term-tag">{{ t(key="manage", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-base">{{ t(key="blog-title", lang=lang | default(value='sk')) }}</h2>
|
||||
<p class="text-sm opacity-70">{{ t(key="admin-blog-desc", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="pt-2">
|
||||
<a href="/admin/blog/articles" class="btn btn-primary btn-sm">[ {{ t(key="blog-manage", lang=lang | default(value='sk')) }} → ]</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">/admin/about</span>
|
||||
<span class="term-head-meta term-tag is-blue">{{ t(key="single", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-base">{{ t(key="about-sub", lang=lang | default(value='sk')) }}</h2>
|
||||
<p class="text-sm opacity-70">{{ t(key="admin-about-desc", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="pt-2">
|
||||
<a href="/admin/about" class="btn btn-primary btn-sm">[ {{ t(key="edit", lang=lang | default(value='sk')) }} → ]</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">/admin/audio</span>
|
||||
<span class="term-head-meta term-tag is-purple">{{ t(key="album", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-base">{{ t(key="audio-title", lang=lang | default(value='sk')) }}</h2>
|
||||
<p class="text-sm opacity-70">{{ t(key="admin-audio-desc", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="pt-2">
|
||||
<a href="/admin/audio/albums" class="btn btn-primary btn-sm">[ {{ t(key="manage", lang=lang | default(value='sk')) }} → ]</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
34
assets/views/admin/login.html
Normal file
@@ -0,0 +1,34 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="login-title", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}admin/login{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
<div class="mx-auto mt-8 max-w-sm">
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">{{ t(key="nav-admin", lang=lang | default(value='sk')) }}</span>
|
||||
<span class="term-head-meta term-tag is-red">{{ t(key="auth", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h1 class="term-title">{{ t(key="login-auth", lang=lang | default(value='sk')) }}</h1>
|
||||
{% if error %}
|
||||
<div class="alert alert-error mt-2">
|
||||
<span>✗ {{ t(key="login-error", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<form method="post" action="/admin/login" hx-boost="false" class="space-y-2">
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">{{ t(key="login-email", lang=lang | default(value='sk')) }}:</span></label>
|
||||
<input type="email" name="email" required autofocus class="input input-bordered w-full">
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text t-green">{{ t(key="login-password", lang=lang | default(value='sk')) }}:</span></label>
|
||||
<input type="password" name="password" required class="input input-bordered w-full">
|
||||
</div>
|
||||
<button class="btn btn-primary mt-2 w-full">[ {{ t(key="login-auth", lang=lang | default(value='sk')) }} ]</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
140
assets/views/audio/album.html
Normal file
@@ -0,0 +1,140 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ album.title }}{% endblock title %}
|
||||
{% block crumb %}audio/{{ album.slug }}{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
{% if logged_in_admin %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ album.title }}</h1>
|
||||
{% if album.artist %}
|
||||
<p class="term-sub">// {{ t(key="album-by", lang=lang | default(value='sk')) }} {{ album.artist }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
{% if tracks | length > 0 %}
|
||||
<button type="button" class="uw-play-album btn btn-primary btn-sm"
|
||||
data-tracks-from="#uw-album-tracks">{{ t(key="album-play-full", lang=lang | default(value='sk')) }}</button>
|
||||
{% endif %}
|
||||
<a href="/audio/albums" class="btn btn-outline btn-sm">[ {{ t(key="cd-up", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% if album.cover_image_id %}
|
||||
<div class="card mb-6">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ album.slug }}/cover.png</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<img src="/images/{{ album.cover_image_id }}" alt="">
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if album.description %}
|
||||
<div class="card mb-6">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ album.slug }}/notes.txt</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="term-prose whitespace-pre-line">{{ album.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ album.slug }}/tracklist</span>
|
||||
<span class="term-head-meta term-tag is-green">{{ tracks | length }} tracks</span>
|
||||
</div>
|
||||
<div class="card-body" id="uw-album-tracks">
|
||||
{% if tracks | length > 0 %}
|
||||
<div class="term-track-bar">
|
||||
<button type="button" class="uw-play-album btn btn-primary btn-sm"
|
||||
data-tracks-from="#uw-album-tracks">{{ t(key="album-play-full", lang=lang | default(value='sk')) }}</button>
|
||||
<span class="term-track-name t-dim">// {{ t(key="album-queue-all", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
{% for track in tracks %}
|
||||
<div class="term-track">
|
||||
<button type="button" class="uw-play btn btn-primary btn-sm"
|
||||
data-src="/audio/tracks/{{ track.id }}/stream" data-title="{{ track.title }}">▶ play</button>
|
||||
<span class="term-track-name">
|
||||
<span class="t-dim">{% if track.track_number %}{{ track.track_number }}{% else %}-{% endif %}</span>
|
||||
<span class="t-green">▸</span> {{ track.title }}
|
||||
</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p class="term-empty-cmd">{{ t(key="album-no-tracks", lang=lang | default(value='sk')) }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ album.title }}</h1>
|
||||
{% if album.artist %}
|
||||
<p class="term-sub">{{ t(key="album-by", lang=lang | default(value='sk')) }} {{ album.artist }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
{% if tracks | length > 0 %}
|
||||
<button type="button" class="uw-play-album btn btn-primary btn-sm"
|
||||
data-tracks-from="#uw-album-tracks">{{ t(key="album-play-full", lang=lang | default(value='sk')) }}</button>
|
||||
{% endif %}
|
||||
<a href="/audio/albums" class="btn btn-outline btn-sm">[ {{ t(key="cd-up", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% if album.cover_image_id %}
|
||||
<div class="card mb-6">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ album.slug }}/cover.png</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<img src="/images/{{ album.cover_image_id }}" alt="">
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if album.description %}
|
||||
<div class="card mb-6">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ album.slug }}/notes.txt</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="term-prose whitespace-pre-line">{{ album.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ album.slug }}/tracklist</span>
|
||||
<span class="term-head-meta term-tag is-green">{{ tracks | length }} tracks</span>
|
||||
</div>
|
||||
<div class="card-body" id="uw-album-tracks">
|
||||
{% if tracks | length > 0 %}
|
||||
<div class="term-track-bar">
|
||||
<button type="button" class="uw-play-album btn btn-primary btn-sm"
|
||||
data-tracks-from="#uw-album-tracks">{{ t(key="album-play-full", lang=lang | default(value='sk')) }}</button>
|
||||
<span class="term-track-name t-dim">// {{ t(key="album-queue-all", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
{% for track in tracks %}
|
||||
<div class="term-track">
|
||||
<button type="button" class="uw-play btn btn-primary btn-sm"
|
||||
data-src="/audio/tracks/{{ track.id }}/stream" data-title="{{ track.title }}">{{ t(key="audio-play", lang=lang | default(value='sk')) }}</button>
|
||||
<span class="term-track-name">
|
||||
<span class="t-dim">{% if track.track_number %}{{ track.track_number }}{% else %}-{% endif %}</span>
|
||||
<span class="t-green">▸</span> {{ track.title }}
|
||||
</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p class="term-empty-cmd">{{ t(key="album-no-tracks", lang=lang | default(value='sk')) }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
96
assets/views/audio/albums.html
Normal file
@@ -0,0 +1,96 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="audio-title", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}audio{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
{% if logged_in_admin %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="audio-title", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">// {{ albums | length }} {{ t(key="audio-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/audio/tracks" class="btn btn-outline btn-sm">[ {{ t(key="audio-all-songs", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% if albums | length > 0 %}
|
||||
<div class="term-grid">
|
||||
{% for album in albums %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ album.slug }}/</span>
|
||||
<span class="term-head-meta term-tag is-purple">{{ t(key="album", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if album.cover_image_id %}
|
||||
<img src="/images/{{ album.cover_image_id }}" alt="" class="mb-3">
|
||||
{% endif %}
|
||||
<h2 class="card-title text-base">{{ album.title }}</h2>
|
||||
{% if album.artist %}
|
||||
<p class="text-sm t-aqua">{{ album.artist }}</p>
|
||||
{% endif %}
|
||||
{% if album.description %}
|
||||
<p class="term-prose text-sm opacity-80">{{ album.description }}</p>
|
||||
{% endif %}
|
||||
<div class="flex flex-wrap gap-2 pt-2">
|
||||
<button type="button" class="uw-play-album-remote btn btn-primary btn-sm"
|
||||
data-album-tracks-url="/audio/albums/{{ album.slug }}/tracks">{{ t(key="audio-play", lang=lang | default(value='sk')) }}</button>
|
||||
<a href="/audio/albums/{{ album.slug }}" class="btn btn-outline btn-sm">{{ t(key="audio-open", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="term-empty">
|
||||
<p class="font-medium">{{ t(key="audio-no-albums", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="audio-title", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">{{ albums | length }} {{ t(key="audio-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/audio/tracks" class="btn btn-outline btn-sm">[ {{ t(key="audio-all-songs", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% if albums | length > 0 %}
|
||||
<div class="term-grid">
|
||||
{% for album in albums %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ album.slug }}/</span>
|
||||
<span class="term-head-meta term-tag is-purple">{{ t(key="album", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if album.cover_image_id %}
|
||||
<img src="/images/{{ album.cover_image_id }}" alt="" class="mb-3">
|
||||
{% endif %}
|
||||
<h2 class="card-title text-base">{{ album.title }}</h2>
|
||||
{% if album.artist %}
|
||||
<p class="text-sm t-aqua">{{ album.artist }}</p>
|
||||
{% endif %}
|
||||
{% if album.description %}
|
||||
<p class="term-prose text-sm opacity-80">{{ album.description }}</p>
|
||||
{% endif %}
|
||||
<div class="flex flex-wrap gap-2 pt-2">
|
||||
<button type="button" class="uw-play-album-remote btn btn-primary btn-sm"
|
||||
data-album-tracks-url="/audio/albums/{{ album.slug }}/tracks">{{ t(key="audio-play", lang=lang | default(value='sk')) }}</button>
|
||||
<a href="/audio/albums/{{ album.slug }}" class="btn btn-outline btn-sm">{{ t(key="audio-open", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="term-empty">
|
||||
<p class="font-medium">{{ t(key="audio-no-albums", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
76
assets/views/audio/tracks.html
Normal file
@@ -0,0 +1,76 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="songs-title", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}audio/tracks{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
{% if logged_in_admin %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="songs-title", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">// {{ tracks | length }} {{ t(key="songs-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
{% if tracks | length > 0 %}
|
||||
<button type="button" class="uw-play-album btn btn-primary btn-sm"
|
||||
data-tracks-from="#uw-songs-list">{{ t(key="songs-play-all", lang=lang | default(value='sk')) }}</button>
|
||||
{% endif %}
|
||||
<a href="/audio/albums" class="btn btn-outline btn-sm">[ {{ t(key="songs-albums", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/playlist.m3u</span>
|
||||
<span class="term-head-meta term-tag is-green">{{ tracks | length }} tracks</span>
|
||||
</div>
|
||||
<div class="card-body" id="uw-songs-list">
|
||||
{% if tracks | length > 0 %}
|
||||
{% for track in tracks %}
|
||||
<div class="term-track">
|
||||
<button type="button" class="uw-play btn btn-primary btn-sm"
|
||||
data-src="/audio/tracks/{{ track.id }}/stream" data-title="{{ track.title }}">{{ t(key="audio-play", lang=lang | default(value='sk')) }}</button>
|
||||
<span class="term-track-name"><span class="t-green">▸</span> {{ track.title }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p class="term-empty-cmd">{{ t(key="songs-no-tracks", lang=lang | default(value='sk')) }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="songs-title", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">{{ tracks | length }} {{ t(key="songs-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
{% if tracks | length > 0 %}
|
||||
<button type="button" class="uw-play-album btn btn-primary btn-sm"
|
||||
data-tracks-from="#uw-songs-list">{{ t(key="songs-play-all", lang=lang | default(value='sk')) }}</button>
|
||||
{% endif %}
|
||||
<a href="/audio/albums" class="btn btn-outline btn-sm">[ {{ t(key="songs-albums", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/playlist.m3u</span>
|
||||
<span class="term-head-meta term-tag is-green">{{ tracks | length }} tracks</span>
|
||||
</div>
|
||||
<div class="card-body" id="uw-songs-list">
|
||||
{% if tracks | length > 0 %}
|
||||
{% for track in tracks %}
|
||||
<div class="term-track">
|
||||
<button type="button" class="uw-play btn btn-primary btn-sm"
|
||||
data-src="/audio/tracks/{{ track.id }}/stream" data-title="{{ track.title }}">{{ t(key="audio-play", lang=lang | default(value='sk')) }}</button>
|
||||
<span class="term-track-name">{{ track.title }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p class="term-empty-cmd">{{ t(key="songs-no-tracks", lang=lang | default(value='sk')) }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
366
assets/views/base.html
Normal file
@@ -0,0 +1,366 @@
|
||||
<!doctype html>
|
||||
<html lang="{{ lang | default(value='sk') }}" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}{{ t(key="brand", lang=lang | default(value='sk')) }}{% endblock title %}</title>
|
||||
<meta name="description" content="{% block meta_description %}{{ t(key="meta-description", lang=lang | default(value='sk')) }}{% endblock meta_description %}">
|
||||
<link rel="icon" type="image/x-icon" href="/static/favicon/favicon.ico">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon/favicon-16x16.png">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon.png">
|
||||
<link rel="manifest" href="/static/favicon/site.webmanifest">
|
||||
<script>
|
||||
function applyTheme(t) {
|
||||
var dark = t === 'dark'
|
||||
|| (t === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
document.documentElement.setAttribute('data-theme', dark ? 'dark' : 'light');
|
||||
}
|
||||
function highlightTheme(t) {
|
||||
document.querySelectorAll('[data-theme-opt]').forEach(function (b) {
|
||||
var on = b.getAttribute('data-theme-opt') === t;
|
||||
b.classList.toggle('active', on);
|
||||
var chk = b.querySelector('.opt-check');
|
||||
if (chk) chk.classList.toggle('hidden', !on);
|
||||
});
|
||||
}
|
||||
function setTheme(t) {
|
||||
localStorage.setItem('theme', t);
|
||||
applyTheme(t);
|
||||
highlightTheme(t);
|
||||
}
|
||||
applyTheme(localStorage.getItem('theme') || 'dark');
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function () {
|
||||
if ((localStorage.getItem('theme') || 'dark') === 'system') applyTheme('system');
|
||||
});
|
||||
function markActiveNav() {
|
||||
var path = location.pathname;
|
||||
document.querySelectorAll('.term-navlinks a[data-nav]').forEach(function (a) {
|
||||
var h = a.getAttribute('data-nav');
|
||||
a.classList.toggle('is-active', h === path || (h !== '/' && path.indexOf(h) === 0));
|
||||
});
|
||||
}
|
||||
function initPage() {
|
||||
highlightTheme(localStorage.getItem('theme') || 'dark');
|
||||
markActiveNav();
|
||||
}
|
||||
// --- persistent audio player with playlist queue ----------
|
||||
// Survives htmx-boosted navigation: window state persists and
|
||||
// #uw-player carries hx-preserve so <audio> keeps playing.
|
||||
var uwQueue = []; // [{ src, title }]
|
||||
var uwIndex = -1; // index of the current track, -1 when empty
|
||||
|
||||
function uwSave() {
|
||||
try {
|
||||
sessionStorage.setItem('uwQueue', JSON.stringify({ q: uwQueue, i: uwIndex }));
|
||||
} catch (e) {}
|
||||
}
|
||||
function uwRestore() {
|
||||
try {
|
||||
var d = JSON.parse(sessionStorage.getItem('uwQueue') || 'null');
|
||||
if (d && d.q) { uwQueue = d.q; uwIndex = (typeof d.i === 'number' ? d.i : -1); }
|
||||
} catch (e) {}
|
||||
}
|
||||
function uwRenderQueue() {
|
||||
var player = document.getElementById('uw-player');
|
||||
if (player) player.classList.toggle('uw-has-queue', uwQueue.length > 0);
|
||||
var badge = document.getElementById('uw-queue-badge');
|
||||
if (badge) badge.textContent = uwQueue.length;
|
||||
var count = document.getElementById('uw-queue-count');
|
||||
if (count) count.textContent = uwQueue.length + (uwQueue.length === 1 ? ' track' : ' tracks');
|
||||
var list = document.getElementById('uw-queue-list');
|
||||
if (!list) return;
|
||||
list.innerHTML = '';
|
||||
uwQueue.forEach(function (t, idx) {
|
||||
var li = document.createElement('li');
|
||||
li.className = 'uw-queue-item' + (idx === uwIndex ? ' is-current' : '');
|
||||
var jump = document.createElement('button');
|
||||
jump.type = 'button';
|
||||
jump.className = 'uw-queue-jump';
|
||||
jump.setAttribute('data-uw-jump', idx);
|
||||
jump.textContent = (idx === uwIndex ? '▸' : (idx + 1));
|
||||
var name = document.createElement('span');
|
||||
name.className = 'uw-queue-name';
|
||||
name.setAttribute('data-uw-jump', idx);
|
||||
name.textContent = t.title || 'unknown track';
|
||||
var rm = document.createElement('button');
|
||||
rm.type = 'button';
|
||||
rm.className = 'uw-queue-remove';
|
||||
rm.setAttribute('data-uw-remove', idx);
|
||||
rm.setAttribute('aria-label', 'Remove from playlist');
|
||||
rm.textContent = '✕';
|
||||
li.appendChild(jump);
|
||||
li.appendChild(name);
|
||||
li.appendChild(rm);
|
||||
list.appendChild(li);
|
||||
});
|
||||
}
|
||||
// Point <audio> at the current queue entry; play it when asked.
|
||||
function uwLoad(autoplay) {
|
||||
var audio = document.getElementById('uw-audio');
|
||||
var now = document.getElementById('uw-now');
|
||||
if (!audio) return;
|
||||
var t = uwQueue[uwIndex];
|
||||
if (!t) {
|
||||
if (now) now.textContent = '—';
|
||||
audio.pause();
|
||||
audio.removeAttribute('src');
|
||||
document.documentElement.classList.remove('uw-playing');
|
||||
uwRenderQueue();
|
||||
uwSave();
|
||||
return;
|
||||
}
|
||||
document.documentElement.classList.add('uw-playing');
|
||||
if (now) now.textContent = t.title || 'unknown track';
|
||||
if (audio.getAttribute('src') !== t.src) {
|
||||
audio.setAttribute('src', t.src);
|
||||
audio.load();
|
||||
}
|
||||
if (autoplay) {
|
||||
var p = audio.play();
|
||||
if (p && p.catch) p.catch(function () {});
|
||||
}
|
||||
uwRenderQueue();
|
||||
uwSave();
|
||||
}
|
||||
// Replace the whole queue with a fresh set of tracks and play.
|
||||
function uwPlayList(tracks) {
|
||||
if (!tracks || !tracks.length) return;
|
||||
uwQueue = tracks.slice();
|
||||
uwIndex = 0;
|
||||
uwLoad(true);
|
||||
}
|
||||
// Add one track: play it now if idle, otherwise queue it.
|
||||
function uwAdd(src, title) {
|
||||
var audio = document.getElementById('uw-audio');
|
||||
var idle = uwIndex < 0 || !audio || audio.ended || !audio.getAttribute('src');
|
||||
uwQueue.push({ src: src, title: title });
|
||||
if (idle) { uwIndex = uwQueue.length - 1; uwLoad(true); }
|
||||
else { uwRenderQueue(); uwSave(); }
|
||||
}
|
||||
function uwNext() {
|
||||
if (uwIndex >= 0 && uwIndex < uwQueue.length - 1) { uwIndex++; uwLoad(true); }
|
||||
}
|
||||
function uwPrev() {
|
||||
var audio = document.getElementById('uw-audio');
|
||||
if (audio && audio.currentTime > 3) { audio.currentTime = 0; return; }
|
||||
if (uwIndex > 0) { uwIndex--; uwLoad(true); }
|
||||
else if (audio) audio.currentTime = 0;
|
||||
}
|
||||
function uwJump(idx) {
|
||||
if (idx >= 0 && idx < uwQueue.length) { uwIndex = idx; uwLoad(true); }
|
||||
}
|
||||
function uwRemove(idx) {
|
||||
if (idx < 0 || idx >= uwQueue.length) return;
|
||||
var playing = document.documentElement.classList.contains('uw-playing');
|
||||
uwQueue.splice(idx, 1);
|
||||
if (idx < uwIndex) { uwIndex--; uwRenderQueue(); uwSave(); }
|
||||
else if (idx > uwIndex) { uwRenderQueue(); uwSave(); }
|
||||
else {
|
||||
if (uwIndex >= uwQueue.length) uwIndex = uwQueue.length - 1;
|
||||
uwLoad(playing);
|
||||
}
|
||||
}
|
||||
function uwClear() {
|
||||
uwQueue = [];
|
||||
uwIndex = -1;
|
||||
uwLoad(false);
|
||||
var panel = document.getElementById('uw-queue');
|
||||
if (panel) panel.hidden = true;
|
||||
}
|
||||
function uwInit() {
|
||||
var audio = document.getElementById('uw-audio');
|
||||
if (!audio || audio.dataset.uwBound) return;
|
||||
audio.dataset.uwBound = '1';
|
||||
uwRestore();
|
||||
audio.addEventListener('ended', uwNext);
|
||||
uwRenderQueue();
|
||||
if (uwIndex >= 0 && uwQueue[uwIndex]) uwLoad(false);
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', function () { initPage(); uwInit(); });
|
||||
document.addEventListener('htmx:afterSwap', initPage);
|
||||
document.addEventListener('click', function (e) {
|
||||
if (!e.target.closest) return;
|
||||
var albumBtn = e.target.closest('.uw-play-album');
|
||||
if (albumBtn) {
|
||||
var sel = albumBtn.getAttribute('data-tracks-from');
|
||||
var scope = (sel && document.querySelector(sel)) || document;
|
||||
var tracks = [];
|
||||
scope.querySelectorAll('.uw-play').forEach(function (b) {
|
||||
tracks.push({ src: b.getAttribute('data-src'), title: b.getAttribute('data-title') });
|
||||
});
|
||||
uwPlayList(tracks);
|
||||
return;
|
||||
}
|
||||
// Play an album straight from the listing: fetch its tracks first.
|
||||
var remoteBtn = e.target.closest('.uw-play-album-remote');
|
||||
if (remoteBtn) {
|
||||
var rurl = remoteBtn.getAttribute('data-album-tracks-url');
|
||||
if (rurl) {
|
||||
remoteBtn.disabled = true;
|
||||
fetch(rurl, { headers: { 'Accept': 'application/json' } })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (d) { if (d && d.tracks) uwPlayList(d.tracks); })
|
||||
.catch(function () {})
|
||||
.then(function () { remoteBtn.disabled = false; });
|
||||
}
|
||||
return;
|
||||
}
|
||||
var playBtn = e.target.closest('.uw-play');
|
||||
if (playBtn) {
|
||||
uwAdd(playBtn.getAttribute('data-src'), playBtn.getAttribute('data-title'));
|
||||
return;
|
||||
}
|
||||
var jumpEl = e.target.closest('[data-uw-jump]');
|
||||
if (jumpEl) { uwJump(parseInt(jumpEl.getAttribute('data-uw-jump'), 10)); return; }
|
||||
var rmEl = e.target.closest('[data-uw-remove]');
|
||||
if (rmEl) { uwRemove(parseInt(rmEl.getAttribute('data-uw-remove'), 10)); return; }
|
||||
if (e.target.closest('#uw-next')) { uwNext(); return; }
|
||||
if (e.target.closest('#uw-prev')) { uwPrev(); return; }
|
||||
if (e.target.closest('#uw-queue-clear')) { uwClear(); return; }
|
||||
if (e.target.closest('#uw-queue-toggle')) {
|
||||
var panel = document.getElementById('uw-queue');
|
||||
if (panel) panel.hidden = !panel.hidden;
|
||||
return;
|
||||
}
|
||||
if (e.target.closest('#uw-close')) { uwClear(); return; }
|
||||
});
|
||||
</script>
|
||||
<link href="/static/css/app.css?v=2026-05-20b" rel="stylesheet" type="text/css">
|
||||
<link href="/static/css/theme.css?v=2026-05-20b" rel="stylesheet" type="text/css">
|
||||
<script src="/static/vendor/htmx/htmx-1.9.12.min.js"></script>
|
||||
<style>
|
||||
@media (min-width: 768px) {
|
||||
.nav-menu { flex-direction: row; }
|
||||
}
|
||||
#nav-backdrop { display: none; }
|
||||
@media (max-width: 767px) {
|
||||
#nav-backdrop {
|
||||
display: block;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 40;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 0.15s ease, visibility 0s linear 0.2s;
|
||||
}
|
||||
.term-titlebar:has(.dropdown:focus-within) ~ #nav-backdrop {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
transition: opacity 0.15s ease, visibility 0s;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body hx-boost="true" class="flex min-h-screen flex-col bg-base-100 text-base-content antialiased">
|
||||
<header class="term-titlebar">
|
||||
<nav class="term-nav">
|
||||
<a href="/" class="term-brand">{{ t(key="brand", lang=lang | default(value='sk')) }}</a>
|
||||
<ul class="nav-menu term-navlinks menu menu-sm hidden items-center md:flex">
|
||||
<li><a href="/" data-nav="/">{{ t(key="nav-home", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/blog" data-nav="/blog">{{ t(key="nav-blog", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/audio/albums" data-nav="/audio/albums">{{ t(key="nav-audio", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/audio/tracks" data-nav="/audio/tracks">{{ t(key="nav-songs", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/about" data-nav="/about">{{ t(key="nav-about", lang=lang | default(value='sk')) }}</a></li>
|
||||
{% if logged_in_admin %}
|
||||
<li><a href="/admin/dashboard" hx-boost="false" class="t-yellow" data-nav="/admin">{{ t(key="admin-title", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li>
|
||||
<form method="post" action="/admin/logout" hx-boost="false">
|
||||
<button type="submit" class="t-red w-full">{{ t(key="logout", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
</li>
|
||||
{% else %}
|
||||
<li><a href="/admin/login" data-nav="/admin/login">{{ t(key="nav-admin", lang=lang | default(value='sk')) }}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<div class="term-nav-right">
|
||||
<div class="dropdown dropdown-end md:hidden">
|
||||
<div tabindex="0" role="button" class="btn btn-ghost btn-sm btn-circle" aria-label="{{ t(key='menu', lang=lang | default(value='sk')) }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||
stroke="currentColor" class="h-5 w-5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
|
||||
</svg>
|
||||
</div>
|
||||
<ul tabindex="0"
|
||||
class="menu dropdown-content z-50 mt-3 w-52 border border-base-300 bg-base-200 p-2 shadow-lg">
|
||||
<li><a href="/">{{ t(key="nav-home", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/blog">{{ t(key="nav-blog", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/audio/albums">{{ t(key="nav-audio", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/audio/tracks">{{ t(key="nav-songs", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li><a href="/about">{{ t(key="nav-about", lang=lang | default(value='sk')) }}</a></li>
|
||||
{% if logged_in_admin %}
|
||||
<li><a href="/admin/dashboard" hx-boost="false" class="t-yellow">{{ t(key="admin-title", lang=lang | default(value='sk')) }}</a></li>
|
||||
<li>
|
||||
<form method="post" action="/admin/logout">
|
||||
<button type="submit" class="t-red w-full">{{ t(key="logout", lang=lang | default(value='sk')) }}</button>
|
||||
</form>
|
||||
</li>
|
||||
{% else %}
|
||||
<li><a href="/admin/login">{{ t(key="nav-admin", lang=lang | default(value='sk')) }}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="dropdown dropdown-end">
|
||||
<div tabindex="0" role="button" class="btn btn-ghost btn-sm btn-circle" aria-label="{{ t(key='settings', lang=lang | default(value='sk')) }}" title="{{ t(key='settings', lang=lang | default(value='sk')) }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||
stroke="currentColor" class="h-5 w-5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round"
|
||||
d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
|
||||
</svg>
|
||||
</div>
|
||||
<form method="post" action="/lang" hx-boost="false">
|
||||
<ul tabindex="0" class="menu dropdown-content z-50 mt-3 w-56 border border-base-300 bg-base-200 p-2 shadow-lg">
|
||||
<li class="menu-title">{{ t(key="settings-language", lang=lang | default(value='sk')) }}</li>
|
||||
<li>
|
||||
<button type="submit" name="lang" value="en" class="{% if lang | default(value='sk') == 'en' %}active{% endif %}">
|
||||
English
|
||||
{% if lang | default(value='sk') == 'en' %}
|
||||
<span class="ml-auto">✓</span>
|
||||
{% endif %}
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button type="submit" name="lang" value="sk" class="{% if lang | default(value='sk') == 'sk' %}active{% endif %}">
|
||||
Slovenčina
|
||||
{% if lang | default(value='sk') == 'sk' %}
|
||||
<span class="ml-auto">✓</span>
|
||||
{% endif %}
|
||||
</button>
|
||||
</li>
|
||||
<li class="menu-title">{{ t(key="settings-theme", lang=lang | default(value='sk')) }}</li>
|
||||
<li><button type="button" data-theme-opt="system" onclick="setTheme('system')">{{ t(key="theme-system", lang=lang | default(value='sk')) }} <span class="opt-check ml-auto hidden">✓</span></button></li>
|
||||
<li><button type="button" data-theme-opt="light" onclick="setTheme('light')">{{ t(key="theme-light", lang=lang | default(value='sk')) }} <span class="opt-check ml-auto hidden">✓</span></button></li>
|
||||
<li><button type="button" data-theme-opt="dark" onclick="setTheme('dark')">{{ t(key="theme-dark", lang=lang | default(value='sk')) }} <span class="opt-check ml-auto hidden">✓</span></button></li>
|
||||
</ul>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div id="nav-backdrop" aria-hidden="true"></div>
|
||||
<main class="term-main">
|
||||
{% block content %}{% endblock content %}
|
||||
</main>
|
||||
<div id="uw-player" hx-preserve="true">
|
||||
<div id="uw-queue" class="uw-queue" hidden>
|
||||
<div class="uw-queue-head">
|
||||
<span class="uw-queue-title">☰ playlist</span>
|
||||
<span id="uw-queue-count" class="uw-queue-meta">0 tracks</span>
|
||||
<button type="button" id="uw-queue-clear" class="uw-queue-clear">clear</button>
|
||||
</div>
|
||||
<ol id="uw-queue-list" class="uw-queue-list"></ol>
|
||||
</div>
|
||||
<div class="uw-player-inner">
|
||||
<span class="uw-player-tag">▶ now playing</span>
|
||||
<span id="uw-now" class="uw-player-title">—</span>
|
||||
<button type="button" id="uw-prev" class="uw-player-btn" aria-label="Previous track" title="Previous">⏮</button>
|
||||
<audio id="uw-audio" controls preload="none"></audio>
|
||||
<button type="button" id="uw-next" class="uw-player-btn" aria-label="Next track" title="Next">⏭</button>
|
||||
<button type="button" id="uw-queue-toggle" class="uw-player-btn" aria-label="Toggle playlist" title="Playlist">☰<span id="uw-queue-badge" class="uw-queue-badge">0</span></button>
|
||||
<button type="button" id="uw-close" class="uw-player-close" aria-label="Stop playback" title="Stop">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
81
assets/views/blog/index.html
Normal file
@@ -0,0 +1,81 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="blog-title", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}blog{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
{% if logged_in_admin %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="blog-title", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">// {{ articles | length }} {{ t(key="blog-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/admin/blog/articles" hx-boost="false" class="btn btn-outline btn-sm">[ {{ t(key="blog-manage", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% if articles | length > 0 %}
|
||||
<div class="term-stack">
|
||||
{% for article in articles %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/blog/{{ article.slug }}.txt</span>
|
||||
<span class="term-head-meta term-tag">{{ t(key="post", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-base">
|
||||
<a href="/blog/{{ article.slug }}">{{ article.title }}</a>
|
||||
</h2>
|
||||
{% if article.excerpt %}
|
||||
<p class="term-prose text-sm opacity-80">{{ article.excerpt }}</p>
|
||||
{% endif %}
|
||||
<div class="pt-2">
|
||||
<a href="/blog/{{ article.slug }}" class="btn btn-primary btn-sm">{{ t(key="blog-read", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="term-empty">
|
||||
<p class="font-medium">{{ t(key="blog-no-posts", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="blog-title", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">{{ articles | length }} {{ t(key="blog-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% if articles | length > 0 %}
|
||||
<div class="term-stack">
|
||||
{% for article in articles %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/blog/{{ article.slug }}.txt</span>
|
||||
<span class="term-head-meta term-tag">{{ t(key="post", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-base">
|
||||
<a href="/blog/{{ article.slug }}">{{ article.title }}</a>
|
||||
</h2>
|
||||
{% if article.excerpt %}
|
||||
<p class="term-prose text-sm opacity-80">{{ article.excerpt }}</p>
|
||||
{% endif %}
|
||||
<div class="pt-2">
|
||||
<a href="/blog/{{ article.slug }}" class="btn btn-primary btn-sm">{{ t(key="blog-read", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="term-empty">
|
||||
<p class="font-medium">{{ t(key="blog-no-posts", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
56
assets/views/blog/show.html
Normal file
@@ -0,0 +1,56 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ article.title }}{% endblock title %}
|
||||
{% block crumb %}blog/{{ article.slug }}{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
{% if logged_in_admin %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ article.title }}</h1>
|
||||
<p class="term-sub">// {{ article.view_count }} {{ t(key="blog-views", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/blog" class="btn btn-outline btn-sm">[ {{ t(key="cd-up", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/blog/{{ article.slug }}.txt</span>
|
||||
<span class="term-head-meta term-tag is-blue">{{ t(key="readonly", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if article.excerpt %}
|
||||
<p class="term-prose t-yellow"># {{ article.excerpt }}</p>
|
||||
<div class="border-t border-base-300 pt-4"></div>
|
||||
{% endif %}
|
||||
<div class="blog-content term-prose">{{ article.content | safe }}</div>
|
||||
</div>
|
||||
</article>
|
||||
{% else %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ article.title }}</h1>
|
||||
<p class="term-sub">{{ article.view_count }} {{ t(key="blog-views", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/blog" class="btn btn-outline btn-sm">[ {{ t(key="cd-up", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/blog/{{ article.slug }}.txt</span>
|
||||
<span class="term-head-meta term-tag is-blue">{{ t(key="readonly", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if article.excerpt %}
|
||||
<p class="term-prose t-yellow"># {{ article.excerpt }}</p>
|
||||
<div class="border-t border-base-300 pt-4"></div>
|
||||
{% endif %}
|
||||
<div class="blog-content term-prose">{{ article.content | safe }}</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
12
assets/views/home/hello.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<html><body>
|
||||
<img src="/static/image.png" width="200"/>
|
||||
<br/>
|
||||
find this tera template at <code>assets/views/home/hello.html</code>:
|
||||
<br/>
|
||||
<br/>
|
||||
{{ t(key="hello-world", lang="sk") }},
|
||||
<br/>
|
||||
{{ t(key="hello-world", lang="en") }}
|
||||
|
||||
</body></html>
|
||||
|
||||
186
assets/views/home/index.html
Normal file
@@ -0,0 +1,186 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ t(key="home-title", lang=lang | default(value='sk')) }}{% endblock title %}
|
||||
{% block crumb %}{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
{% if logged_in_admin %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="home-title", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">// {{ t(key="home-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/blog" class="btn btn-outline btn-sm">[ {{ t(key="home-all-posts", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% if featured_track or featured_album %}
|
||||
<section class="mb-8">
|
||||
<p class="term-cmd-line mb-6"><span class="t-dim"># </span>{{ t(key="home-picks", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="term-grid">
|
||||
{% if featured_track %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/tracks/{{ featured_track.slug }}</span>
|
||||
<span class="term-head-meta term-tag is-green">{{ t(key="song", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="term-track">
|
||||
<button type="button" class="uw-play btn btn-primary btn-sm"
|
||||
data-src="/audio/tracks/{{ featured_track.id }}/stream" data-title="{{ featured_track.title }}">{{ t(key="audio-play", lang=lang | default(value='sk')) }}</button>
|
||||
<span class="term-track-name"><span class="t-green">▸</span> {{ featured_track.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endif %}
|
||||
{% if featured_album %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ featured_album.slug }}/</span>
|
||||
<span class="term-head-meta term-tag is-purple">{{ t(key="album", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if featured_album.cover_image_id %}
|
||||
<img src="/images/{{ featured_album.cover_image_id }}" alt="" class="mb-3">
|
||||
{% endif %}
|
||||
<h2 class="card-title text-base">{{ featured_album.title }}</h2>
|
||||
{% if featured_album.artist %}
|
||||
<p class="text-sm t-aqua">{{ featured_album.artist }}</p>
|
||||
{% endif %}
|
||||
{% if featured_album.description %}
|
||||
<p class="term-prose text-sm opacity-80">{{ featured_album.description }}</p>
|
||||
{% endif %}
|
||||
<div class="flex flex-wrap gap-2 pt-2">
|
||||
<button type="button" class="uw-play-album-remote btn btn-primary btn-sm"
|
||||
data-album-tracks-url="/audio/albums/{{ featured_album.slug }}/tracks">{{ t(key="audio-play", lang=lang | default(value='sk')) }}</button>
|
||||
<a href="/audio/albums/{{ featured_album.slug }}" class="btn btn-outline btn-sm">{{ t(key="audio-open", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endif %}
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
<section>
|
||||
<p class="term-cmd-line mb-6"><span class="t-dim"># </span>{{ t(key="home-recent", lang=lang | default(value='sk')) }} <span class="t-dim">({{ articles | length }})</span></p>
|
||||
{% if articles | length > 0 %}
|
||||
<div class="term-stack">
|
||||
{% for article in articles %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/blog/{{ article.slug }}.txt</span>
|
||||
<span class="term-head-meta term-tag">{{ t(key="post", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-base">
|
||||
<a href="/blog/{{ article.slug }}">{{ article.title }}</a>
|
||||
</h2>
|
||||
{% if article.excerpt %}
|
||||
<p class="term-prose text-sm opacity-80">{{ article.excerpt }}</p>
|
||||
{% endif %}
|
||||
<div class="pt-2">
|
||||
<a href="/blog/{{ article.slug }}" class="btn btn-primary btn-sm">{{ t(key="blog-read", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="term-empty">
|
||||
<p class="font-medium">{{ t(key="home-no-posts", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% else %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ t(key="home-title", lang=lang | default(value='sk')) }}</h1>
|
||||
<p class="term-sub">{{ t(key="home-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/blog" class="btn btn-outline btn-sm">{{ t(key="home-all-posts", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% if featured_track or featured_album %}
|
||||
<section class="mb-8">
|
||||
<p class="term-cmd-line mb-6"><span class="t-dim"># </span>{{ t(key="home-picks", lang=lang | default(value='sk')) }}</p>
|
||||
<div class="term-grid">
|
||||
{% if featured_track %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/tracks/{{ featured_track.slug }}</span>
|
||||
<span class="term-head-meta term-tag is-green">{{ t(key="song", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="term-track">
|
||||
<button type="button" class="uw-play btn btn-primary btn-sm"
|
||||
data-src="/audio/tracks/{{ featured_track.id }}/stream" data-title="{{ featured_track.title }}">{{ t(key="audio-play", lang=lang | default(value='sk')) }}</button>
|
||||
<span class="term-track-name"><span class="t-green">▸</span> {{ featured_track.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endif %}
|
||||
{% if featured_album %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/audio/{{ featured_album.slug }}/</span>
|
||||
<span class="term-head-meta term-tag is-purple">{{ t(key="album", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if featured_album.cover_image_id %}
|
||||
<img src="/images/{{ featured_album.cover_image_id }}" alt="" class="mb-3">
|
||||
{% endif %}
|
||||
<h2 class="card-title text-base">{{ featured_album.title }}</h2>
|
||||
{% if featured_album.artist %}
|
||||
<p class="text-sm t-aqua">{{ featured_album.artist }}</p>
|
||||
{% endif %}
|
||||
{% if featured_album.description %}
|
||||
<p class="term-prose text-sm opacity-80">{{ featured_album.description }}</p>
|
||||
{% endif %}
|
||||
<div class="flex flex-wrap gap-2 pt-2">
|
||||
<button type="button" class="uw-play-album-remote btn btn-primary btn-sm"
|
||||
data-album-tracks-url="/audio/albums/{{ featured_album.slug }}/tracks">{{ t(key="audio-play", lang=lang | default(value='sk')) }}</button>
|
||||
<a href="/audio/albums/{{ featured_album.slug }}" class="btn btn-outline btn-sm">{{ t(key="audio-open", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endif %}
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
<section>
|
||||
<p class="term-cmd-line mb-6"><span class="t-dim"># </span>{{ t(key="home-recent", lang=lang | default(value='sk')) }} <span class="t-dim">({{ articles | length }})</span></p>
|
||||
{% if articles | length > 0 %}
|
||||
<div class="term-stack">
|
||||
{% for article in articles %}
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/blog/{{ article.slug }}.txt</span>
|
||||
<span class="term-head-meta term-tag">{{ t(key="post", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-base">
|
||||
<a href="/blog/{{ article.slug }}">{{ article.title }}</a>
|
||||
</h2>
|
||||
{% if article.excerpt %}
|
||||
<p class="text-sm opacity-80">{{ article.excerpt }}</p>
|
||||
{% endif %}
|
||||
<div class="pt-2">
|
||||
<a href="/blog/{{ article.slug }}" class="btn btn-primary btn-sm">{{ t(key="blog-read", lang=lang | default(value='sk')) }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="term-empty">
|
||||
<p class="font-medium">{{ t(key="home-no-posts", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
45
assets/views/pages/about.html
Normal file
@@ -0,0 +1,45 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ page.title }}{% endblock title %}
|
||||
{% block crumb %}about{% endblock crumb %}
|
||||
|
||||
{% block content %}
|
||||
{% if logged_in_admin %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ page.title }}</h1>
|
||||
<p class="term-sub">// {{ t(key="about-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
<div class="term-cmd-actions">
|
||||
<a href="/admin/about" hx-boost="false" class="btn btn-outline btn-sm">[ {{ t(key="edit", lang=lang | default(value='sk')) }} ]</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/about.txt</span>
|
||||
<span class="term-head-meta term-tag is-blue">{{ t(key="readonly", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="term-prose whitespace-pre-line">{{ page.content }}</div>
|
||||
</div>
|
||||
</article>
|
||||
{% else %}
|
||||
<header class="term-cmd">
|
||||
<div>
|
||||
<h1 class="term-title">{{ page.title }}</h1>
|
||||
<p class="term-sub">{{ t(key="about-sub", lang=lang | default(value='sk')) }}</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<article class="card">
|
||||
<div class="term-head">
|
||||
<span class="term-head-name">~/about.txt</span>
|
||||
<span class="term-head-meta term-tag is-blue">{{ t(key="readonly", lang=lang | default(value='sk')) }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="term-prose whitespace-pre-line">{{ page.content }}</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
107
config/development.yaml
Normal file
@@ -0,0 +1,107 @@
|
||||
# Loco configuration file documentation
|
||||
|
||||
# Application logging configuration
|
||||
logger:
|
||||
# Enable or disable logging.
|
||||
enable: true
|
||||
# Enable pretty backtrace (sets RUST_BACKTRACE=1)
|
||||
pretty_backtrace: true
|
||||
# Log level, options: trace, debug, info, warn or error.
|
||||
level: debug
|
||||
# Define the logging format. options: compact, pretty or json
|
||||
format: compact
|
||||
# By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries
|
||||
# Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters.
|
||||
# override_filter: trace
|
||||
|
||||
# Web server configuration
|
||||
server:
|
||||
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
|
||||
port: 5150
|
||||
# Binding for the server (which interface to bind to)
|
||||
binding: localhost
|
||||
# The UI hostname or IP address that mailers will point to.
|
||||
host: http://localhost
|
||||
# Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block
|
||||
middlewares:
|
||||
static:
|
||||
enable: true
|
||||
must_exist: true
|
||||
precompressed: false
|
||||
folder:
|
||||
uri: "/static"
|
||||
path: "assets/static"
|
||||
fallback: "assets/static/404.html"
|
||||
|
||||
# Worker Configuration
|
||||
workers:
|
||||
# specifies the worker mode. Options:
|
||||
# - BackgroundQueue - Workers operate asynchronously in the background, processing queued.
|
||||
# - ForegroundBlocking - Workers operate in the foreground and block until tasks are completed.
|
||||
# - BackgroundAsync - Workers operate asynchronously in the background, processing tasks with async capabilities.
|
||||
mode: BackgroundAsync
|
||||
|
||||
|
||||
|
||||
# Mailer Configuration.
|
||||
mailer:
|
||||
# SMTP mailer configuration.
|
||||
smtp:
|
||||
# Enable/Disable smtp mailer.
|
||||
enable: true
|
||||
# SMTP server host. e.x localhost, smtp.gmail.com
|
||||
host: localhost
|
||||
# SMTP server port
|
||||
port: 1025
|
||||
# Use secure connection (SSL/TLS).
|
||||
secure: false
|
||||
# auth:
|
||||
# user:
|
||||
# password:
|
||||
# Override the SMTP hello name (default is the machine's hostname)
|
||||
# hello_name:
|
||||
|
||||
# Initializers Configuration
|
||||
# initializers:
|
||||
# oauth2:
|
||||
# authorization_code: # Authorization code grant type
|
||||
# - client_identifier: google # Identifier for the OAuth2 provider. Replace 'google' with your provider's name if different, must be unique within the oauth2 config.
|
||||
# ... other fields
|
||||
|
||||
# Database Configuration
|
||||
database:
|
||||
# Database connection URI
|
||||
uri: {{ get_env(name="DATABASE_URL", default="postgres://uni_loco_web_user:3@localhost:5432/gitara_web_development") }}
|
||||
# When enabled, the sql query will be logged.
|
||||
enable_logging: false
|
||||
# Set the timeout duration when acquiring a connection.
|
||||
connect_timeout: {{ get_env(name="DB_CONNECT_TIMEOUT", default="500") }}
|
||||
# Set the idle duration before closing a connection.
|
||||
idle_timeout: {{ get_env(name="DB_IDLE_TIMEOUT", default="500") }}
|
||||
# Minimum number of connections for a pool.
|
||||
min_connections: {{ get_env(name="DB_MIN_CONNECTIONS", default="1") }}
|
||||
# Maximum number of connections for a pool.
|
||||
max_connections: {{ get_env(name="DB_MAX_CONNECTIONS", default="1") }}
|
||||
# Run migration up when application loaded
|
||||
auto_migrate: true
|
||||
# Truncate database when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode
|
||||
dangerously_truncate: false
|
||||
# Recreating schema when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode
|
||||
dangerously_recreate: false
|
||||
|
||||
# Authentication Configuration
|
||||
auth:
|
||||
# JWT authentication
|
||||
jwt:
|
||||
location:
|
||||
- from: Cookie
|
||||
name: auth_token
|
||||
- from: Bearer
|
||||
# Secret key for token generation and verification
|
||||
secret: A6ECni63rt2Jb00tX9Hf
|
||||
# Token expiration time in seconds
|
||||
expiration: 604800 # 7 days
|
||||
|
||||
settings:
|
||||
admin_email: {{ get_env(name="ADMIN_EMAIL", default="admin@example.com") }}
|
||||
uploads_root: {{ get_env(name="UPLOADS_ROOT", default="uploads") }}
|
||||
57
config/production.yaml
Normal file
@@ -0,0 +1,57 @@
|
||||
logger:
|
||||
enable: true
|
||||
pretty_backtrace: false
|
||||
level: "{{ get_env(name="LOG_LEVEL", default="info") }}"
|
||||
format: "{{ get_env(name="LOG_FORMAT", default="compact") }}"
|
||||
|
||||
server:
|
||||
port: {{ get_env(name="PORT", default="5150") }}
|
||||
binding: "{{ get_env(name="SERVER_BINDING", default="0.0.0.0") }}"
|
||||
host: "{{ get_env(name="APP_HOST") }}"
|
||||
middlewares:
|
||||
static:
|
||||
enable: true
|
||||
must_exist: true
|
||||
precompressed: false
|
||||
folder:
|
||||
uri: "/static"
|
||||
path: "assets/static"
|
||||
fallback: "assets/static/404.html"
|
||||
|
||||
workers:
|
||||
mode: "{{ get_env(name="WORKER_MODE", default="BackgroundAsync") }}"
|
||||
|
||||
mailer:
|
||||
stub: {{ get_env(name="MAILER_STUB", default="true") }}
|
||||
smtp:
|
||||
enable: {{ get_env(name="SMTP_ENABLE", default="false") }}
|
||||
host: "{{ get_env(name="SMTP_HOST", default="localhost") }}"
|
||||
port: {{ get_env(name="SMTP_PORT", default="1025") }}
|
||||
secure: {{ get_env(name="SMTP_SECURE", default="false") }}
|
||||
auth:
|
||||
user: "{{ get_env(name="SMTP_USER", default="") }}"
|
||||
password: "{{ get_env(name="SMTP_PASSWORD", default="") }}"
|
||||
|
||||
database:
|
||||
uri: "{{ get_env(name="DATABASE_URL") }}"
|
||||
enable_logging: {{ get_env(name="DB_ENABLE_LOGGING", default="false") }}
|
||||
connect_timeout: {{ get_env(name="DB_CONNECT_TIMEOUT", default="500") }}
|
||||
idle_timeout: {{ get_env(name="DB_IDLE_TIMEOUT", default="500") }}
|
||||
min_connections: {{ get_env(name="DB_MIN_CONNECTIONS", default="1") }}
|
||||
max_connections: {{ get_env(name="DB_MAX_CONNECTIONS", default="5") }}
|
||||
auto_migrate: {{ get_env(name="DB_AUTO_MIGRATE", default="true") }}
|
||||
dangerously_truncate: false
|
||||
dangerously_recreate: false
|
||||
|
||||
auth:
|
||||
jwt:
|
||||
location:
|
||||
- from: Cookie
|
||||
name: auth_token
|
||||
- from: Bearer
|
||||
secret: "{{ get_env(name="JWT_SECRET") }}"
|
||||
expiration: {{ get_env(name="JWT_EXPIRATION", default="604800") }}
|
||||
|
||||
settings:
|
||||
admin_email: "{{ get_env(name="ADMIN_EMAIL", default="") }}"
|
||||
uploads_root: "{{ get_env(name="UPLOADS_ROOT", default="data/uploads") }}"
|
||||
104
config/test.yaml
Normal file
@@ -0,0 +1,104 @@
|
||||
# Loco configuration file documentation
|
||||
|
||||
# Application logging configuration
|
||||
logger:
|
||||
# Enable or disable logging.
|
||||
enable: false
|
||||
# Enable pretty backtrace (sets RUST_BACKTRACE=1)
|
||||
pretty_backtrace: true
|
||||
# Log level, options: trace, debug, info, warn or error.
|
||||
level: debug
|
||||
# Define the logging format. options: compact, pretty or json
|
||||
format: compact
|
||||
# By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries
|
||||
# Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters.
|
||||
# override_filter: trace
|
||||
|
||||
# Web server configuration
|
||||
server:
|
||||
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
|
||||
port: 5150
|
||||
# The UI hostname or IP address that mailers will point to.
|
||||
host: http://localhost
|
||||
# Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block
|
||||
middlewares:
|
||||
static:
|
||||
enable: true
|
||||
must_exist: true
|
||||
precompressed: false
|
||||
folder:
|
||||
uri: "/static"
|
||||
path: "assets/static"
|
||||
fallback: "assets/static/404.html"
|
||||
|
||||
# Worker Configuration
|
||||
workers:
|
||||
# specifies the worker mode. Options:
|
||||
# - BackgroundQueue - Workers operate asynchronously in the background, processing queued.
|
||||
# - ForegroundBlocking - Workers operate in the foreground and block until tasks are completed.
|
||||
# - BackgroundAsync - Workers operate asynchronously in the background, processing tasks with async capabilities.
|
||||
mode: ForegroundBlocking
|
||||
|
||||
|
||||
|
||||
# Mailer Configuration.
|
||||
mailer:
|
||||
stub: true
|
||||
# SMTP mailer configuration.
|
||||
smtp:
|
||||
# Enable/Disable smtp mailer.
|
||||
enable: true
|
||||
# SMTP server host. e.x localhost, smtp.gmail.com
|
||||
host: localhost
|
||||
# SMTP server port
|
||||
port: 1025
|
||||
# Use secure connection (SSL/TLS).
|
||||
secure: false
|
||||
# auth:
|
||||
# user:
|
||||
# password:
|
||||
|
||||
# Initializers Configuration
|
||||
# initializers:
|
||||
# oauth2:
|
||||
# authorization_code: # Authorization code grant type
|
||||
# - client_identifier: google # Identifier for the OAuth2 provider. Replace 'google' with your provider's name if different, must be unique within the oauth2 config.
|
||||
# ... other fields
|
||||
|
||||
# Database Configuration
|
||||
database:
|
||||
# Database connection URI
|
||||
uri: {{ get_env(name="DATABASE_URL", default="postgres://uni_loco_web_user:3@localhost:5432/gitara_web_test") }}
|
||||
# When enabled, the sql query will be logged.
|
||||
enable_logging: false
|
||||
# Set the timeout duration when acquiring a connection.
|
||||
connect_timeout: {{ get_env(name="DB_CONNECT_TIMEOUT", default="500") }}
|
||||
# Set the idle duration before closing a connection.
|
||||
idle_timeout: {{ get_env(name="DB_IDLE_TIMEOUT", default="500") }}
|
||||
# Minimum number of connections for a pool.
|
||||
min_connections: {{ get_env(name="DB_MIN_CONNECTIONS", default="1") }}
|
||||
# Maximum number of connections for a pool.
|
||||
max_connections: {{ get_env(name="DB_MAX_CONNECTIONS", default="1") }}
|
||||
# Run migration up when application loaded
|
||||
auto_migrate: true
|
||||
# Truncate database when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode
|
||||
dangerously_truncate: true
|
||||
# Recreating schema when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode
|
||||
dangerously_recreate: true
|
||||
|
||||
# Authentication Configuration
|
||||
auth:
|
||||
# JWT authentication
|
||||
jwt:
|
||||
location:
|
||||
- from: Cookie
|
||||
name: auth_token
|
||||
- from: Bearer
|
||||
# Secret key for token generation and verification
|
||||
secret: 0yWwoflcGiAhonIzhQyQ
|
||||
# Token expiration time in seconds
|
||||
expiration: 604800 # 7 days
|
||||
|
||||
settings:
|
||||
admin_email: admin@example.com
|
||||
uploads_root: uploads/test
|
||||
30
docker-compose.prod.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
services:
|
||||
gitara-web:
|
||||
container_name: gitara-web
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
env_file:
|
||||
- .env.production
|
||||
volumes:
|
||||
- gitara_web_data:/usr/app/data
|
||||
networks:
|
||||
- gitara-net
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "curl -fsS http://localhost:5150/_ping"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 20s
|
||||
|
||||
networks:
|
||||
gitara-net:
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
gitara_web_data:
|
||||
external: true
|
||||
name: gitara_web_data
|
||||
21
examples/playground.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
#[allow(unused_imports)]
|
||||
use loco_rs::{cli::playground, prelude::*};
|
||||
use gitara_web::app::App;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> loco_rs::Result<()> {
|
||||
let _ctx = playground::<App>().await?;
|
||||
|
||||
// let active_model: articles::ActiveModel = articles::ActiveModel {
|
||||
// title: Set(Some("how to build apps in 3 steps".to_string())),
|
||||
// content: Set(Some("use Loco: https://loco.rs".to_string())),
|
||||
// ..Default::default()
|
||||
// };
|
||||
// active_model.insert(&ctx.db).await.unwrap();
|
||||
|
||||
// let res = articles::Entity::find().all(&ctx.db).await.unwrap();
|
||||
// println!("{:?}", res);
|
||||
println!("welcome to playground. edit me at `examples/playground.rs`");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
BIN
favicon/android-chrome-192x192.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
favicon/android-chrome-512x512.png
Normal file
|
After Width: | Height: | Size: 187 KiB |
BIN
favicon/apple-touch-icon.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
favicon/favicon-16x16.png
Normal file
|
After Width: | Height: | Size: 601 B |
BIN
favicon/favicon-32x32.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
favicon/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
1
favicon/site.webmanifest
Normal file
@@ -0,0 +1 @@
|
||||
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
|
||||
22
migration/Cargo.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "migration"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
name = "migration"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
loco-rs = { workspace = true }
|
||||
|
||||
|
||||
[dependencies.sea-orm-migration]
|
||||
version = "1.1.0"
|
||||
features = [
|
||||
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
|
||||
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
|
||||
# e.g.
|
||||
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
|
||||
]
|
||||
40
migration/src/lib.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
#![allow(elided_lifetimes_in_paths)]
|
||||
#![allow(clippy::wildcard_imports)]
|
||||
pub use sea_orm_migration::prelude::*;
|
||||
mod m20220101_000001_users;
|
||||
mod m20260517_000001_add_theme_to_users;
|
||||
mod m20260517_000002_user_roles;
|
||||
mod m20260517_000003_blog_articles;
|
||||
mod m20260517_000004_audit_logs;
|
||||
mod m20260517_000005_audio_albums;
|
||||
mod m20260517_000006_audio_tracks;
|
||||
mod m20260517_000007_audio_tags;
|
||||
mod m20260517_000008_audio_track_tags;
|
||||
mod m20260517_000009_simple_constraints;
|
||||
mod m20260517_000010_drop_user_roles;
|
||||
mod m20260517_000011_site_pages;
|
||||
mod m20260517_000012_standalone_audio_tracks;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20220101_000001_users::Migration),
|
||||
Box::new(m20260517_000001_add_theme_to_users::Migration),
|
||||
Box::new(m20260517_000002_user_roles::Migration),
|
||||
Box::new(m20260517_000003_blog_articles::Migration),
|
||||
Box::new(m20260517_000004_audit_logs::Migration),
|
||||
Box::new(m20260517_000005_audio_albums::Migration),
|
||||
Box::new(m20260517_000006_audio_tracks::Migration),
|
||||
Box::new(m20260517_000007_audio_tags::Migration),
|
||||
Box::new(m20260517_000008_audio_track_tags::Migration),
|
||||
Box::new(m20260517_000009_simple_constraints::Migration),
|
||||
Box::new(m20260517_000010_drop_user_roles::Migration),
|
||||
Box::new(m20260517_000011_site_pages::Migration),
|
||||
Box::new(m20260517_000012_standalone_audio_tracks::Migration),
|
||||
// inject-above (do not remove this comment)
|
||||
]
|
||||
}
|
||||
}
|
||||
41
migration/src/m20220101_000001_users.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"users",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("pid", ColType::Uuid),
|
||||
("email", ColType::StringUniq),
|
||||
("password", ColType::String),
|
||||
("api_key", ColType::StringUniq),
|
||||
("name", ColType::String),
|
||||
("reset_token", ColType::StringNull),
|
||||
("reset_sent_at", ColType::TimestampWithTimeZoneNull),
|
||||
("email_verification_token", ColType::StringNull),
|
||||
(
|
||||
"email_verification_sent_at",
|
||||
ColType::TimestampWithTimeZoneNull,
|
||||
),
|
||||
("email_verified_at", ColType::TimestampWithTimeZoneNull),
|
||||
("magic_link_token", ColType::StringNull),
|
||||
("magic_link_expiration", ColType::TimestampWithTimeZoneNull),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "users").await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
24
migration/src/m20260517_000001_add_theme_to_users.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
add_column(
|
||||
m,
|
||||
"users",
|
||||
"theme",
|
||||
ColType::StringLenWithDefault(20, "light".to_string()),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
remove_column(m, "users", "theme").await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
97
migration/src/m20260517_000002_user_roles.rs
Normal file
@@ -0,0 +1,97 @@
|
||||
use sea_orm_migration::{prelude::*, sea_orm::ConnectionTrait, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum UserRoles {
|
||||
Table,
|
||||
UserId,
|
||||
Role,
|
||||
AssignedBy,
|
||||
AssignedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Users {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_table(
|
||||
Table::create()
|
||||
.table(UserRoles::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(UserRoles::UserId).integer().not_null())
|
||||
.col(ColumnDef::new(UserRoles::Role).string_len(50).not_null())
|
||||
.col(ColumnDef::new(UserRoles::AssignedBy).integer().null())
|
||||
.col(
|
||||
ColumnDef::new(UserRoles::AssignedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.primary_key(
|
||||
Index::create()
|
||||
.name("pk-user_roles")
|
||||
.col(UserRoles::UserId)
|
||||
.col(UserRoles::Role),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-user_roles-user_id-to-users")
|
||||
.from(UserRoles::Table, UserRoles::UserId)
|
||||
.to(Users::Table, Users::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-user_roles-assigned_by-to-users")
|
||||
.from(UserRoles::Table, UserRoles::AssignedBy)
|
||||
.to(Users::Table, Users::Id)
|
||||
.on_delete(ForeignKeyAction::SetNull)
|
||||
.on_update(ForeignKeyAction::NoAction),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name("idx-user_roles-user_id")
|
||||
.table(UserRoles::Table)
|
||||
.col(UserRoles::UserId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let sql = match m.get_database_backend() {
|
||||
sea_orm_migration::sea_orm::DatabaseBackend::Postgres => {
|
||||
"INSERT INTO user_roles (user_id, role, assigned_at) \
|
||||
SELECT id, 'user', CURRENT_TIMESTAMP FROM users \
|
||||
ON CONFLICT (user_id, role) DO NOTHING"
|
||||
}
|
||||
sea_orm_migration::sea_orm::DatabaseBackend::Sqlite => {
|
||||
"INSERT OR IGNORE INTO user_roles (user_id, role, assigned_at) \
|
||||
SELECT id, 'user', CURRENT_TIMESTAMP FROM users"
|
||||
}
|
||||
sea_orm_migration::sea_orm::DatabaseBackend::MySql => {
|
||||
"INSERT IGNORE INTO user_roles (user_id, role, assigned_at) \
|
||||
SELECT id, 'user', CURRENT_TIMESTAMP FROM users"
|
||||
}
|
||||
};
|
||||
m.get_connection().execute_unprepared(sql).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(Table::drop().table(UserRoles::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
139
migration/src/m20260517_000003_blog_articles.rs
Normal file
@@ -0,0 +1,139 @@
|
||||
use sea_orm_migration::{prelude::*, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum BlogArticles {
|
||||
Table,
|
||||
Id,
|
||||
Title,
|
||||
Slug,
|
||||
Content,
|
||||
Excerpt,
|
||||
Published,
|
||||
AuthorId,
|
||||
FeaturedImageId,
|
||||
ViewCount,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
PublishedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Users {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_table(
|
||||
Table::create()
|
||||
.table(BlogArticles::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::Title)
|
||||
.string_len(500)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::Slug)
|
||||
.string_len(500)
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(BlogArticles::Content).text().not_null())
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::Excerpt)
|
||||
.string_len(1000)
|
||||
.null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::Published)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.col(ColumnDef::new(BlogArticles::AuthorId).integer().not_null())
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::FeaturedImageId)
|
||||
.string_len(500)
|
||||
.null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::ViewCount)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(BlogArticles::PublishedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.null(),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-blog_articles-author_id-to-users")
|
||||
.from(BlogArticles::Table, BlogArticles::AuthorId)
|
||||
.to(Users::Table, Users::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
create_index(m, "idx-blog_articles-slug", BlogArticles::Slug).await?;
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name("idx-blog_articles-published-published_at")
|
||||
.table(BlogArticles::Table)
|
||||
.col(BlogArticles::Published)
|
||||
.col(BlogArticles::PublishedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
create_index(m, "idx-blog_articles-author_id", BlogArticles::AuthorId).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(Table::drop().table(BlogArticles::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_index<T>(m: &SchemaManager<'_>, name: &str, col: T) -> Result<(), DbErr>
|
||||
where
|
||||
T: Iden + 'static,
|
||||
{
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name(name)
|
||||
.table(BlogArticles::Table)
|
||||
.col(col)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
98
migration/src/m20260517_000004_audit_logs.rs
Normal file
@@ -0,0 +1,98 @@
|
||||
use sea_orm_migration::{prelude::*, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AuditLogs {
|
||||
Table,
|
||||
Id,
|
||||
AdminUserId,
|
||||
Action,
|
||||
TargetType,
|
||||
TargetId,
|
||||
Details,
|
||||
IpAddress,
|
||||
UserAgent,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Users {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_table(
|
||||
Table::create()
|
||||
.table(AuditLogs::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(AuditLogs::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(AuditLogs::AdminUserId).integer().not_null())
|
||||
.col(ColumnDef::new(AuditLogs::Action).string_len(100).not_null())
|
||||
.col(ColumnDef::new(AuditLogs::TargetType).string_len(50).null())
|
||||
.col(ColumnDef::new(AuditLogs::TargetId).uuid().null())
|
||||
.col(ColumnDef::new(AuditLogs::Details).json_binary().null())
|
||||
.col(ColumnDef::new(AuditLogs::IpAddress).inet().null())
|
||||
.col(ColumnDef::new(AuditLogs::UserAgent).text().null())
|
||||
.col(
|
||||
ColumnDef::new(AuditLogs::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-audit_logs-admin_user_id-to-users")
|
||||
.from(AuditLogs::Table, AuditLogs::AdminUserId)
|
||||
.to(Users::Table, Users::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
create_index(m, "idx-audit_logs-admin_user_id", AuditLogs::AdminUserId).await?;
|
||||
create_index(m, "idx-audit_logs-action", AuditLogs::Action).await?;
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name("idx-audit_logs-target")
|
||||
.table(AuditLogs::Table)
|
||||
.col(AuditLogs::TargetType)
|
||||
.col(AuditLogs::TargetId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
create_index(m, "idx-audit_logs-created_at", AuditLogs::CreatedAt).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(Table::drop().table(AuditLogs::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_index<T>(m: &SchemaManager<'_>, name: &str, col: T) -> Result<(), DbErr>
|
||||
where
|
||||
T: Iden + 'static,
|
||||
{
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name(name)
|
||||
.table(AuditLogs::Table)
|
||||
.col(col)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
129
migration/src/m20260517_000005_audio_albums.rs
Normal file
@@ -0,0 +1,129 @@
|
||||
use sea_orm_migration::{prelude::*, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioAlbums {
|
||||
Table,
|
||||
Id,
|
||||
Title,
|
||||
Slug,
|
||||
Description,
|
||||
CoverImageId,
|
||||
Artist,
|
||||
ReleaseDate,
|
||||
Published,
|
||||
UploaderId,
|
||||
ViewCount,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
PublishedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Users {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_table(
|
||||
Table::create()
|
||||
.table(AudioAlbums::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(AudioAlbums::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioAlbums::Title)
|
||||
.string_len(500)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioAlbums::Slug)
|
||||
.string_len(500)
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(AudioAlbums::Description).text().null())
|
||||
.col(
|
||||
ColumnDef::new(AudioAlbums::CoverImageId)
|
||||
.string_len(500)
|
||||
.null(),
|
||||
)
|
||||
.col(ColumnDef::new(AudioAlbums::Artist).string_len(500).null())
|
||||
.col(ColumnDef::new(AudioAlbums::ReleaseDate).date().null())
|
||||
.col(
|
||||
ColumnDef::new(AudioAlbums::Published)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.col(ColumnDef::new(AudioAlbums::UploaderId).integer().not_null())
|
||||
.col(
|
||||
ColumnDef::new(AudioAlbums::ViewCount)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioAlbums::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioAlbums::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioAlbums::PublishedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.null(),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-audio_albums-uploader_id-to-users")
|
||||
.from(AudioAlbums::Table, AudioAlbums::UploaderId)
|
||||
.to(Users::Table, Users::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
create_index(m, "idx-audio_albums-slug", AudioAlbums::Slug).await?;
|
||||
create_index(m, "idx-audio_albums-published", AudioAlbums::Published).await?;
|
||||
create_index(m, "idx-audio_albums-uploader_id", AudioAlbums::UploaderId).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(Table::drop().table(AudioAlbums::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_index<T>(m: &SchemaManager<'_>, name: &str, col: T) -> Result<(), DbErr>
|
||||
where
|
||||
T: Iden + 'static,
|
||||
{
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name(name)
|
||||
.table(AudioAlbums::Table)
|
||||
.col(col)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
109
migration/src/m20260517_000006_audio_tracks.rs
Normal file
@@ -0,0 +1,109 @@
|
||||
use sea_orm_migration::{prelude::*, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioTracks {
|
||||
Table,
|
||||
Id,
|
||||
AlbumId,
|
||||
Title,
|
||||
Slug,
|
||||
AudioFileId,
|
||||
TrackNumber,
|
||||
Duration,
|
||||
Featured,
|
||||
PlayCount,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioAlbums {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_table(
|
||||
Table::create()
|
||||
.table(AudioTracks::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(AudioTracks::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(AudioTracks::AlbumId).uuid().not_null())
|
||||
.col(
|
||||
ColumnDef::new(AudioTracks::Title)
|
||||
.string_len(500)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(AudioTracks::Slug).string_len(500).not_null())
|
||||
.col(
|
||||
ColumnDef::new(AudioTracks::AudioFileId)
|
||||
.string_len(500)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(AudioTracks::TrackNumber).integer().null())
|
||||
.col(ColumnDef::new(AudioTracks::Duration).integer().null())
|
||||
.col(
|
||||
ColumnDef::new(AudioTracks::Featured)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioTracks::PlayCount)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioTracks::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioTracks::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-audio_tracks-album_id-to-audio_albums")
|
||||
.from(AudioTracks::Table, AudioTracks::AlbumId)
|
||||
.to(AudioAlbums::Table, AudioAlbums::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name("idx-audio_tracks-album_id-slug")
|
||||
.table(AudioTracks::Table)
|
||||
.col(AudioTracks::AlbumId)
|
||||
.col(AudioTracks::Slug)
|
||||
.unique()
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(Table::drop().table(AudioTracks::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
57
migration/src/m20260517_000007_audio_tags.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use sea_orm_migration::{prelude::*, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioTags {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
Slug,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_table(
|
||||
Table::create()
|
||||
.table(AudioTags::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(AudioTags::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioTags::Name)
|
||||
.string_len(100)
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioTags::Slug)
|
||||
.string_len(100)
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AudioTags::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(Table::drop().table(AudioTags::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
74
migration/src/m20260517_000008_audio_track_tags.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use sea_orm_migration::{prelude::*, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioTrackTags {
|
||||
Table,
|
||||
TrackId,
|
||||
TagId,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioTracks {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioTags {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_table(
|
||||
Table::create()
|
||||
.table(AudioTrackTags::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(AudioTrackTags::TrackId).uuid().not_null())
|
||||
.col(ColumnDef::new(AudioTrackTags::TagId).uuid().not_null())
|
||||
.col(
|
||||
ColumnDef::new(AudioTrackTags::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.primary_key(
|
||||
Index::create()
|
||||
.name("pk-audio_track_tags")
|
||||
.col(AudioTrackTags::TrackId)
|
||||
.col(AudioTrackTags::TagId),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-audio_track_tags-track_id-to-audio_tracks")
|
||||
.from(AudioTrackTags::Table, AudioTrackTags::TrackId)
|
||||
.to(AudioTracks::Table, AudioTracks::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-audio_track_tags-tag_id-to-audio_tags")
|
||||
.from(AudioTrackTags::Table, AudioTrackTags::TagId)
|
||||
.to(AudioTags::Table, AudioTags::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(Table::drop().table(AudioTrackTags::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
60
migration/src/m20260517_000009_simple_constraints.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use sea_orm_migration::{prelude::*, sea_orm::ConnectionTrait};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioTrackTags {
|
||||
Table,
|
||||
TagId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
if matches!(
|
||||
m.get_database_backend(),
|
||||
sea_orm_migration::sea_orm::DatabaseBackend::Postgres
|
||||
) {
|
||||
m.get_connection()
|
||||
.execute_unprepared(
|
||||
"ALTER TABLE users \
|
||||
ADD CONSTRAINT chk_users_theme \
|
||||
CHECK (theme IN ('light', 'dark'))",
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name("idx-audio_track_tags-tag_id")
|
||||
.table(AudioTrackTags::Table)
|
||||
.col(AudioTrackTags::TagId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_index(
|
||||
Index::drop()
|
||||
.name("idx-audio_track_tags-tag_id")
|
||||
.table(AudioTrackTags::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
if matches!(
|
||||
m.get_database_backend(),
|
||||
sea_orm_migration::sea_orm::DatabaseBackend::Postgres
|
||||
) {
|
||||
m.get_connection()
|
||||
.execute_unprepared("ALTER TABLE users DROP CONSTRAINT chk_users_theme")
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
28
migration/src/m20260517_000010_drop_user_roles.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum UserRoles {
|
||||
Table,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(
|
||||
Table::drop()
|
||||
.table(UserRoles::Table)
|
||||
.if_exists()
|
||||
.cascade()
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, _m: &SchemaManager) -> Result<(), DbErr> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
70
migration/src/m20260517_000011_site_pages.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use sea_orm_migration::{prelude::*, sea_orm::ConnectionTrait, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum SitePages {
|
||||
Table,
|
||||
Id,
|
||||
Slug,
|
||||
Title,
|
||||
Content,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_table(
|
||||
Table::create()
|
||||
.table(SitePages::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(SitePages::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(SitePages::Slug)
|
||||
.string_len(100)
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(SitePages::Title).string_len(500).not_null())
|
||||
.col(ColumnDef::new(SitePages::Content).text().not_null())
|
||||
.col(
|
||||
ColumnDef::new(SitePages::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(SitePages::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.get_connection()
|
||||
.execute_unprepared(
|
||||
"INSERT INTO site_pages (id, slug, title, content, created_at, updated_at) \
|
||||
VALUES (gen_random_uuid(), 'about', 'About', '', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) \
|
||||
ON CONFLICT (slug) DO NOTHING",
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(Table::drop().table(SitePages::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
131
migration/src/m20260517_000012_standalone_audio_tracks.rs
Normal file
@@ -0,0 +1,131 @@
|
||||
use sea_orm_migration::{prelude::*, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioTracks {
|
||||
Table,
|
||||
AlbumId,
|
||||
Published,
|
||||
PublishedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum AudioAlbums {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_foreign_key(
|
||||
ForeignKey::drop()
|
||||
.name("fk-audio_tracks-album_id-to-audio_albums")
|
||||
.table(AudioTracks::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.alter_table(
|
||||
Table::alter()
|
||||
.table(AudioTracks::Table)
|
||||
.modify_column(ColumnDef::new(AudioTracks::AlbumId).uuid().null())
|
||||
.add_column(
|
||||
ColumnDef::new(AudioTracks::Published)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.add_column(
|
||||
ColumnDef::new(AudioTracks::PublishedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.create_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-audio_tracks-album_id-to-audio_albums")
|
||||
.from(AudioTracks::Table, AudioTracks::AlbumId)
|
||||
.to(AudioAlbums::Table, AudioAlbums::Id)
|
||||
.on_delete(ForeignKeyAction::SetNull)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
UPDATE audio_tracks t
|
||||
SET published = TRUE,
|
||||
published_at = COALESCE(a.published_at, CURRENT_TIMESTAMP)
|
||||
FROM audio_albums a
|
||||
WHERE t.album_id = a.id
|
||||
AND a.published = TRUE
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name("idx-audio_tracks-published")
|
||||
.table(AudioTracks::Table)
|
||||
.col(AudioTracks::Published)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_index(
|
||||
Index::drop()
|
||||
.name("idx-audio_tracks-published")
|
||||
.table(AudioTracks::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.drop_foreign_key(
|
||||
ForeignKey::drop()
|
||||
.name("fk-audio_tracks-album_id-to-audio_albums")
|
||||
.table(AudioTracks::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.alter_table(
|
||||
Table::alter()
|
||||
.table(AudioTracks::Table)
|
||||
.drop_column(AudioTracks::PublishedAt)
|
||||
.drop_column(AudioTracks::Published)
|
||||
.modify_column(
|
||||
ColumnDef::new(AudioTracks::AlbumId)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.default(Expr::cust("'00000000-0000-0000-0000-000000000000'::uuid")),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.create_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-audio_tracks-album_id-to-audio_albums")
|
||||
.from(AudioTracks::Table, AudioTracks::AlbumId)
|
||||
.to(AudioAlbums::Table, AudioAlbums::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
100
src/app.rs
Normal file
@@ -0,0 +1,100 @@
|
||||
use async_trait::async_trait;
|
||||
use loco_rs::{
|
||||
app::{AppContext, Hooks, Initializer},
|
||||
bgworker::{BackgroundWorker, Queue},
|
||||
boot::{create_app, BootResult, StartMode},
|
||||
config::Config,
|
||||
controller::AppRoutes,
|
||||
db::{self, truncate_table},
|
||||
environment::Environment,
|
||||
storage::{self, Storage},
|
||||
task::Tasks,
|
||||
Result,
|
||||
};
|
||||
use migration::Migrator;
|
||||
use std::{path::Path, sync::Arc};
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use crate::{
|
||||
controllers, initializers, models::_entities::users, tasks, workers::downloader::DownloadWorker,
|
||||
};
|
||||
|
||||
pub struct App;
|
||||
#[async_trait]
|
||||
impl Hooks for App {
|
||||
fn app_name() -> &'static str {
|
||||
env!("CARGO_CRATE_NAME")
|
||||
}
|
||||
|
||||
fn app_version() -> String {
|
||||
format!(
|
||||
"{} ({})",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
option_env!("BUILD_SHA")
|
||||
.or(option_env!("GITHUB_SHA"))
|
||||
.unwrap_or("dev")
|
||||
)
|
||||
}
|
||||
|
||||
async fn boot(
|
||||
mode: StartMode,
|
||||
environment: &Environment,
|
||||
config: Config,
|
||||
) -> Result<BootResult> {
|
||||
create_app::<Self, Migrator>(mode, environment, config).await
|
||||
}
|
||||
|
||||
async fn load_config(environment: &Environment) -> Result<Config> {
|
||||
dotenvy::dotenv().ok();
|
||||
environment.load()
|
||||
}
|
||||
|
||||
async fn initializers(_ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
|
||||
Ok(vec![
|
||||
Box::new(initializers::view_engine::ViewEngineInitializer),
|
||||
Box::new(initializers::admin_seeder::AdminSeeder),
|
||||
])
|
||||
}
|
||||
|
||||
fn routes(_ctx: &AppContext) -> AppRoutes {
|
||||
AppRoutes::with_default_routes() // controller routes below
|
||||
.add_route(controllers::auth::routes())
|
||||
.add_route(controllers::admin::routes())
|
||||
.add_route(controllers::blog::routes())
|
||||
.add_route(controllers::i18n::routes())
|
||||
.add_route(controllers::media::routes())
|
||||
.add_route(controllers::pages::routes())
|
||||
.add_route(controllers::frontend::routes())
|
||||
}
|
||||
|
||||
async fn after_context(ctx: AppContext) -> Result<AppContext> {
|
||||
let upload_root = crate::controllers::media::uploads_root(&ctx.config)?;
|
||||
tokio::fs::create_dir_all(upload_root.join(controllers::media::AUDIO_STORAGE_DIR)).await?;
|
||||
tokio::fs::create_dir_all(upload_root.join(controllers::media::IMAGE_STORAGE_DIR)).await?;
|
||||
|
||||
let driver = storage::drivers::local::new_with_prefix(&upload_root)?;
|
||||
Ok(AppContext {
|
||||
storage: Arc::new(Storage::single(driver)),
|
||||
..ctx
|
||||
})
|
||||
}
|
||||
|
||||
async fn connect_workers(ctx: &AppContext, queue: &Queue) -> Result<()> {
|
||||
queue.register(DownloadWorker::build(ctx)).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn register_tasks(tasks: &mut Tasks) {
|
||||
// tasks-inject (do not remove)
|
||||
}
|
||||
async fn truncate(ctx: &AppContext) -> Result<()> {
|
||||
truncate_table(&ctx.db, users::Entity).await?;
|
||||
Ok(())
|
||||
}
|
||||
async fn seed(ctx: &AppContext, base: &Path) -> Result<()> {
|
||||
db::seed::<users::ActiveModel>(&ctx.db, &base.join("users.yaml").display().to_string())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
8
src/bin/main.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use loco_rs::cli;
|
||||
use migration::Migrator;
|
||||
use gitara_web::app::App;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> loco_rs::Result<()> {
|
||||
cli::main::<App, Migrator>().await
|
||||
}
|
||||
57
src/controllers/admin.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use crate::models::{
|
||||
_entities::{audio_albums, audio_tracks, audit_logs, blog_articles, users},
|
||||
users as users_model,
|
||||
};
|
||||
use loco_rs::prelude::*;
|
||||
use sea_orm::{EntityTrait, PaginatorTrait};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct DashboardResponse {
|
||||
users: u64,
|
||||
blog_articles: u64,
|
||||
audio_albums: u64,
|
||||
audio_tracks: u64,
|
||||
audit_logs: u64,
|
||||
}
|
||||
|
||||
pub(crate) fn admin_email(ctx: &AppContext) -> Option<&str> {
|
||||
ctx.config
|
||||
.settings
|
||||
.as_ref()
|
||||
.and_then(|settings| settings.get("admin_email"))
|
||||
.and_then(|email| email.as_str())
|
||||
}
|
||||
|
||||
pub(crate) fn is_admin(ctx: &AppContext, user: &users::Model) -> bool {
|
||||
admin_email(ctx).is_some_and(|email| user.email.eq_ignore_ascii_case(email))
|
||||
}
|
||||
|
||||
pub(crate) async fn current_admin(auth: auth::JWT, ctx: &AppContext) -> Result<users::Model> {
|
||||
let user = users_model::Model::find_by_pid(&ctx.db, &auth.claims.pid).await?;
|
||||
|
||||
if !is_admin(ctx, &user) {
|
||||
return unauthorized("admin only");
|
||||
}
|
||||
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn dashboard(auth: auth::JWT, State(ctx): State<AppContext>) -> Result<Response> {
|
||||
current_admin(auth, &ctx).await?;
|
||||
|
||||
format::json(DashboardResponse {
|
||||
users: users::Entity::find().count(&ctx.db).await?,
|
||||
blog_articles: blog_articles::Entity::find().count(&ctx.db).await?,
|
||||
audio_albums: audio_albums::Entity::find().count(&ctx.db).await?,
|
||||
audio_tracks: audio_tracks::Entity::find().count(&ctx.db).await?,
|
||||
audit_logs: audit_logs::Entity::find().count(&ctx.db).await?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn routes() -> Routes {
|
||||
Routes::new()
|
||||
.prefix("/api/admin")
|
||||
.add("/dashboard", get(dashboard))
|
||||
}
|
||||
316
src/controllers/auth.rs
Normal file
@@ -0,0 +1,316 @@
|
||||
use crate::{
|
||||
mailers::auth::AuthMailer,
|
||||
models::{
|
||||
_entities::users,
|
||||
users::{LoginParams, RegisterParams},
|
||||
},
|
||||
views::auth::{CurrentResponse, LoginResponse},
|
||||
};
|
||||
use axum_extra::extract::cookie::{Cookie, SameSite};
|
||||
use loco_rs::prelude::*;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::OnceLock;
|
||||
use time::Duration as TimeDuration;
|
||||
|
||||
pub static EMAIL_DOMAIN_RE: OnceLock<Regex> = OnceLock::new();
|
||||
pub(crate) const AUTH_COOKIE: &str = "auth_token";
|
||||
|
||||
fn get_allow_email_domain_re() -> &'static Regex {
|
||||
EMAIL_DOMAIN_RE.get_or_init(|| {
|
||||
Regex::new(r"@example\.com$|@gmail\.com$").expect("Failed to compile regex")
|
||||
})
|
||||
}
|
||||
|
||||
fn admin_email(ctx: &AppContext) -> Option<&str> {
|
||||
ctx.config
|
||||
.settings
|
||||
.as_ref()
|
||||
.and_then(|settings| settings.get("admin_email"))
|
||||
.and_then(|email| email.as_str())
|
||||
}
|
||||
|
||||
fn is_admin(ctx: &AppContext, user: &users::Model) -> bool {
|
||||
admin_email(ctx).is_some_and(|email| user.email.eq_ignore_ascii_case(email))
|
||||
}
|
||||
|
||||
pub(crate) fn auth_cookie(token: &str, max_age_seconds: u64) -> Cookie<'static> {
|
||||
Cookie::build((AUTH_COOKIE, token.to_string()))
|
||||
.path("/")
|
||||
.http_only(true)
|
||||
.same_site(SameSite::Lax)
|
||||
.max_age(TimeDuration::seconds(max_age_seconds as i64))
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn clear_auth_cookie() -> Cookie<'static> {
|
||||
Cookie::build((AUTH_COOKIE, ""))
|
||||
.path("/")
|
||||
.http_only(true)
|
||||
.same_site(SameSite::Lax)
|
||||
.max_age(TimeDuration::seconds(0))
|
||||
.build()
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ForgotParams {
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ResetParams {
|
||||
pub token: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct MagicLinkParams {
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ResendVerificationParams {
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
/// Register function creates a new user with the given parameters and sends a
|
||||
/// welcome email to the user
|
||||
#[debug_handler]
|
||||
async fn register(
|
||||
State(ctx): State<AppContext>,
|
||||
Json(params): Json<RegisterParams>,
|
||||
) -> Result<Response> {
|
||||
let res = users::Model::create_with_password(&ctx.db, ¶ms).await;
|
||||
|
||||
let user = match res {
|
||||
Ok(user) => user,
|
||||
Err(err) => {
|
||||
tracing::info!(
|
||||
message = err.to_string(),
|
||||
user_email = ¶ms.email,
|
||||
"could not register user",
|
||||
);
|
||||
return format::json(());
|
||||
}
|
||||
};
|
||||
|
||||
let user = user
|
||||
.into_active_model()
|
||||
.set_email_verification_sent(&ctx.db)
|
||||
.await?;
|
||||
|
||||
AuthMailer::send_welcome(&ctx, &user).await?;
|
||||
|
||||
format::json(())
|
||||
}
|
||||
|
||||
/// Verify register user. if the user not verified his email, he can't login to
|
||||
/// the system.
|
||||
#[debug_handler]
|
||||
async fn verify(State(ctx): State<AppContext>, Path(token): Path<String>) -> Result<Response> {
|
||||
let Ok(user) = users::Model::find_by_verification_token(&ctx.db, &token).await else {
|
||||
return unauthorized("invalid token");
|
||||
};
|
||||
|
||||
if user.email_verified_at.is_some() {
|
||||
tracing::info!(pid = user.pid.to_string(), "user already verified");
|
||||
} else {
|
||||
let active_model = user.into_active_model();
|
||||
let user = active_model.verified(&ctx.db).await?;
|
||||
tracing::info!(pid = user.pid.to_string(), "user verified");
|
||||
}
|
||||
|
||||
format::json(())
|
||||
}
|
||||
|
||||
/// In case the user forgot his password this endpoints generate a forgot token
|
||||
/// and send email to the user. In case the email not found in our DB, we are
|
||||
/// returning a valid request for for security reasons (not exposing users DB
|
||||
/// list).
|
||||
#[debug_handler]
|
||||
async fn forgot(
|
||||
State(ctx): State<AppContext>,
|
||||
Json(params): Json<ForgotParams>,
|
||||
) -> Result<Response> {
|
||||
let Ok(user) = users::Model::find_by_email(&ctx.db, ¶ms.email).await else {
|
||||
// we don't want to expose our users email. if the email is invalid we still
|
||||
// returning success to the caller
|
||||
return format::json(());
|
||||
};
|
||||
|
||||
let user = user
|
||||
.into_active_model()
|
||||
.set_forgot_password_sent(&ctx.db)
|
||||
.await?;
|
||||
|
||||
AuthMailer::forgot_password(&ctx, &user).await?;
|
||||
|
||||
format::json(())
|
||||
}
|
||||
|
||||
/// reset user password by the given parameters
|
||||
#[debug_handler]
|
||||
async fn reset(State(ctx): State<AppContext>, Json(params): Json<ResetParams>) -> Result<Response> {
|
||||
let Ok(user) = users::Model::find_by_reset_token(&ctx.db, ¶ms.token).await else {
|
||||
// we don't want to expose our users email. if the email is invalid we still
|
||||
// returning success to the caller
|
||||
tracing::info!("reset token not found");
|
||||
|
||||
return format::json(());
|
||||
};
|
||||
user.into_active_model()
|
||||
.reset_password(&ctx.db, ¶ms.password)
|
||||
.await?;
|
||||
|
||||
format::json(())
|
||||
}
|
||||
|
||||
/// Creates a user login and returns a token
|
||||
#[debug_handler]
|
||||
async fn login(State(ctx): State<AppContext>, Json(params): Json<LoginParams>) -> Result<Response> {
|
||||
let Ok(user) = users::Model::find_by_email(&ctx.db, ¶ms.email).await else {
|
||||
tracing::debug!(
|
||||
email = params.email,
|
||||
"login attempt with non-existent email"
|
||||
);
|
||||
return unauthorized("Invalid credentials!");
|
||||
};
|
||||
|
||||
let valid = user.verify_password(¶ms.password);
|
||||
|
||||
if !valid {
|
||||
return unauthorized("unauthorized!");
|
||||
}
|
||||
|
||||
let jwt_secret = ctx.config.get_jwt_config()?;
|
||||
|
||||
let token = user
|
||||
.generate_jwt(&jwt_secret.secret, jwt_secret.expiration)
|
||||
.or_else(|_| unauthorized("unauthorized!"))?;
|
||||
|
||||
format::render()
|
||||
.cookies(&[auth_cookie(&token, jwt_secret.expiration)])?
|
||||
.json(LoginResponse::new(&user, &token, is_admin(&ctx, &user)))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn current(auth: auth::JWT, State(ctx): State<AppContext>) -> Result<Response> {
|
||||
let user = users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await?;
|
||||
format::json(CurrentResponse::new(&user, is_admin(&ctx, &user)))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn logout() -> Result<Response> {
|
||||
format::render().cookies(&[clear_auth_cookie()])?.json(())
|
||||
}
|
||||
|
||||
/// Magic link authentication provides a secure and passwordless way to log in to the application.
|
||||
///
|
||||
/// # Flow
|
||||
/// 1. **Request a Magic Link**:
|
||||
/// A registered user sends a POST request to `/magic-link` with their email.
|
||||
/// If the email exists, a short-lived, one-time-use token is generated and sent to the user's email.
|
||||
/// For security and to avoid exposing whether an email exists, the response always returns 200, even if the email is invalid.
|
||||
///
|
||||
/// 2. **Click the Magic Link**:
|
||||
/// The user clicks the link (/magic-link/{token}), which validates the token and its expiration.
|
||||
/// If valid, the server generates a JWT and responds with a [`LoginResponse`].
|
||||
/// If invalid or expired, an unauthorized response is returned.
|
||||
///
|
||||
/// This flow enhances security by avoiding traditional passwords and providing a seamless login experience.
|
||||
async fn magic_link(
|
||||
State(ctx): State<AppContext>,
|
||||
Json(params): Json<MagicLinkParams>,
|
||||
) -> Result<Response> {
|
||||
let email_regex = get_allow_email_domain_re();
|
||||
if !email_regex.is_match(¶ms.email) {
|
||||
tracing::debug!(
|
||||
email = params.email,
|
||||
"The provided email is invalid or does not match the allowed domains"
|
||||
);
|
||||
return bad_request("invalid request");
|
||||
}
|
||||
|
||||
let Ok(user) = users::Model::find_by_email(&ctx.db, ¶ms.email).await else {
|
||||
// we don't want to expose our users email. if the email is invalid we still
|
||||
// returning success to the caller
|
||||
tracing::debug!(email = params.email, "user not found by email");
|
||||
return format::empty_json();
|
||||
};
|
||||
|
||||
let user = user.into_active_model().create_magic_link(&ctx.db).await?;
|
||||
AuthMailer::send_magic_link(&ctx, &user).await?;
|
||||
|
||||
format::empty_json()
|
||||
}
|
||||
|
||||
/// Verifies a magic link token and authenticates the user.
|
||||
async fn magic_link_verify(
|
||||
Path(token): Path<String>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
let Ok(user) = users::Model::find_by_magic_token(&ctx.db, &token).await else {
|
||||
// we don't want to expose our users email. if the email is invalid we still
|
||||
// returning success to the caller
|
||||
return unauthorized("unauthorized!");
|
||||
};
|
||||
|
||||
let user = user.into_active_model().clear_magic_link(&ctx.db).await?;
|
||||
|
||||
let jwt_secret = ctx.config.get_jwt_config()?;
|
||||
|
||||
let token = user
|
||||
.generate_jwt(&jwt_secret.secret, jwt_secret.expiration)
|
||||
.or_else(|_| unauthorized("unauthorized!"))?;
|
||||
|
||||
format::render()
|
||||
.cookies(&[auth_cookie(&token, jwt_secret.expiration)])?
|
||||
.json(LoginResponse::new(&user, &token, is_admin(&ctx, &user)))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn resend_verification_email(
|
||||
State(ctx): State<AppContext>,
|
||||
Json(params): Json<ResendVerificationParams>,
|
||||
) -> Result<Response> {
|
||||
let Ok(user) = users::Model::find_by_email(&ctx.db, ¶ms.email).await else {
|
||||
tracing::info!(
|
||||
email = params.email,
|
||||
"User not found for resend verification"
|
||||
);
|
||||
return format::json(());
|
||||
};
|
||||
|
||||
if user.email_verified_at.is_some() {
|
||||
tracing::info!(
|
||||
pid = user.pid.to_string(),
|
||||
"User already verified, skipping resend"
|
||||
);
|
||||
return format::json(());
|
||||
}
|
||||
|
||||
let user = user
|
||||
.into_active_model()
|
||||
.set_email_verification_sent(&ctx.db)
|
||||
.await?;
|
||||
|
||||
AuthMailer::send_welcome(&ctx, &user).await?;
|
||||
tracing::info!(pid = user.pid.to_string(), "Verification email re-sent");
|
||||
|
||||
format::json(())
|
||||
}
|
||||
|
||||
pub fn routes() -> Routes {
|
||||
Routes::new()
|
||||
.prefix("/api/auth")
|
||||
.add("/register", post(register))
|
||||
.add("/verify/{token}", get(verify))
|
||||
.add("/login", post(login))
|
||||
.add("/logout", post(logout))
|
||||
.add("/forgot", post(forgot))
|
||||
.add("/reset", post(reset))
|
||||
.add("/current", get(current))
|
||||
.add("/magic-link", post(magic_link))
|
||||
.add("/magic-link/{token}", get(magic_link_verify))
|
||||
.add("/resend-verification-mail", post(resend_verification_email))
|
||||
}
|
||||
245
src/controllers/blog.rs
Normal file
@@ -0,0 +1,245 @@
|
||||
use crate::{controllers::admin, models::_entities::blog_articles};
|
||||
use chrono::Utc;
|
||||
use loco_rs::prelude::*;
|
||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, QueryOrder, Set};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ArticleParams {
|
||||
title: String,
|
||||
content: String,
|
||||
excerpt: Option<String>,
|
||||
published: Option<bool>,
|
||||
featured_image_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct ArticleResponse {
|
||||
id: Uuid,
|
||||
title: String,
|
||||
slug: String,
|
||||
content: String,
|
||||
excerpt: Option<String>,
|
||||
published: bool,
|
||||
author_id: i32,
|
||||
featured_image_id: Option<String>,
|
||||
view_count: i32,
|
||||
created_at: chrono::DateTime<chrono::FixedOffset>,
|
||||
updated_at: chrono::DateTime<chrono::FixedOffset>,
|
||||
published_at: Option<chrono::DateTime<chrono::FixedOffset>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct ArticleListResponse {
|
||||
articles: Vec<ArticleResponse>,
|
||||
}
|
||||
|
||||
impl From<blog_articles::Model> for ArticleResponse {
|
||||
fn from(article: blog_articles::Model) -> Self {
|
||||
Self {
|
||||
id: article.id,
|
||||
title: article.title,
|
||||
slug: article.slug,
|
||||
content: article.content,
|
||||
excerpt: article.excerpt,
|
||||
published: article.published,
|
||||
author_id: article.author_id,
|
||||
featured_image_id: article.featured_image_id,
|
||||
view_count: article.view_count,
|
||||
created_at: article.created_at,
|
||||
updated_at: article.updated_at,
|
||||
published_at: article.published_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn slugify(title: &str) -> String {
|
||||
let mut slug = String::new();
|
||||
let mut last_was_dash = false;
|
||||
|
||||
for ch in title.chars().flat_map(char::to_lowercase) {
|
||||
if ch.is_ascii_alphanumeric() {
|
||||
slug.push(ch);
|
||||
last_was_dash = false;
|
||||
} else if !last_was_dash && !slug.is_empty() {
|
||||
slug.push('-');
|
||||
last_was_dash = true;
|
||||
}
|
||||
}
|
||||
|
||||
let slug = slug.trim_matches('-').to_string();
|
||||
if slug.is_empty() {
|
||||
Uuid::new_v4().to_string()
|
||||
} else {
|
||||
slug
|
||||
}
|
||||
}
|
||||
|
||||
fn published_at_for(published: bool) -> Option<chrono::DateTime<chrono::FixedOffset>> {
|
||||
published.then(|| Utc::now().into())
|
||||
}
|
||||
|
||||
async fn find_article_by_id(ctx: &AppContext, id: Uuid) -> Result<blog_articles::Model> {
|
||||
blog_articles::Entity::find_by_id(id)
|
||||
.one(&ctx.db)
|
||||
.await?
|
||||
.ok_or_else(|| Error::NotFound)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn public_index(State(ctx): State<AppContext>) -> Result<Response> {
|
||||
let articles = blog_articles::Entity::find()
|
||||
.filter(blog_articles::Column::Published.eq(true))
|
||||
.order_by_desc(blog_articles::Column::PublishedAt)
|
||||
.all(&ctx.db)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(ArticleResponse::from)
|
||||
.collect();
|
||||
|
||||
format::json(ArticleListResponse { articles })
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn public_show(Path(slug): Path<String>, State(ctx): State<AppContext>) -> Result<Response> {
|
||||
let article = blog_articles::Entity::find()
|
||||
.filter(blog_articles::Column::Slug.eq(slug))
|
||||
.filter(blog_articles::Column::Published.eq(true))
|
||||
.one(&ctx.db)
|
||||
.await?
|
||||
.ok_or_else(|| Error::NotFound)?;
|
||||
|
||||
let mut active = article.into_active_model();
|
||||
let next_count = active.view_count.as_ref().to_owned() + 1;
|
||||
active.view_count = Set(next_count);
|
||||
let article = active.update(&ctx.db).await?;
|
||||
|
||||
format::json(ArticleResponse::from(article))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_index(auth: auth::JWT, State(ctx): State<AppContext>) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
|
||||
let articles = blog_articles::Entity::find()
|
||||
.order_by_desc(blog_articles::Column::CreatedAt)
|
||||
.all(&ctx.db)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(ArticleResponse::from)
|
||||
.collect();
|
||||
|
||||
format::json(ArticleListResponse { articles })
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_create(
|
||||
auth: auth::JWT,
|
||||
State(ctx): State<AppContext>,
|
||||
Json(params): Json<ArticleParams>,
|
||||
) -> Result<Response> {
|
||||
let admin_user = admin::current_admin(auth, &ctx).await?;
|
||||
let published = params.published.unwrap_or(false);
|
||||
|
||||
let article = blog_articles::ActiveModel {
|
||||
id: Set(Uuid::new_v4()),
|
||||
title: Set(params.title.clone()),
|
||||
slug: Set(slugify(¶ms.title)),
|
||||
content: Set(params.content),
|
||||
excerpt: Set(params.excerpt),
|
||||
published: Set(published),
|
||||
author_id: Set(admin_user.id),
|
||||
featured_image_id: Set(params.featured_image_id),
|
||||
view_count: Set(0),
|
||||
published_at: Set(published_at_for(published)),
|
||||
..Default::default()
|
||||
}
|
||||
.insert(&ctx.db)
|
||||
.await?;
|
||||
|
||||
format::json(ArticleResponse::from(article))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_update(
|
||||
auth: auth::JWT,
|
||||
Path(id): Path<Uuid>,
|
||||
State(ctx): State<AppContext>,
|
||||
Json(params): Json<ArticleParams>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
|
||||
let existing = find_article_by_id(&ctx, id).await?;
|
||||
let was_published = existing.published;
|
||||
let published = params.published.unwrap_or(was_published);
|
||||
|
||||
let mut article = existing.into_active_model();
|
||||
article.title = Set(params.title.clone());
|
||||
article.slug = Set(slugify(¶ms.title));
|
||||
article.content = Set(params.content);
|
||||
article.excerpt = Set(params.excerpt);
|
||||
article.published = Set(published);
|
||||
article.featured_image_id = Set(params.featured_image_id);
|
||||
if published && !was_published {
|
||||
article.published_at = Set(published_at_for(true));
|
||||
} else if !published {
|
||||
article.published_at = Set(None);
|
||||
}
|
||||
|
||||
let article = article.update(&ctx.db).await?;
|
||||
format::json(ArticleResponse::from(article))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_delete(
|
||||
auth: auth::JWT,
|
||||
Path(id): Path<Uuid>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
let article = find_article_by_id(&ctx, id).await?;
|
||||
article.delete(&ctx.db).await?;
|
||||
format::json(())
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_publish(
|
||||
auth: auth::JWT,
|
||||
Path(id): Path<Uuid>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
let mut article = find_article_by_id(&ctx, id).await?.into_active_model();
|
||||
article.published = Set(true);
|
||||
article.published_at = Set(published_at_for(true));
|
||||
let article = article.update(&ctx.db).await?;
|
||||
format::json(ArticleResponse::from(article))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_unpublish(
|
||||
auth: auth::JWT,
|
||||
Path(id): Path<Uuid>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
let mut article = find_article_by_id(&ctx, id).await?.into_active_model();
|
||||
article.published = Set(false);
|
||||
article.published_at = Set(None);
|
||||
let article = article.update(&ctx.db).await?;
|
||||
format::json(ArticleResponse::from(article))
|
||||
}
|
||||
|
||||
pub fn routes() -> Routes {
|
||||
Routes::new()
|
||||
.prefix("/api")
|
||||
.add("/blog", get(public_index))
|
||||
.add("/blog/{slug}", get(public_show))
|
||||
.add("/admin/blog/articles", get(admin_index))
|
||||
.add("/admin/blog/articles", post(admin_create))
|
||||
.add("/admin/blog/articles/{id}", put(admin_update))
|
||||
.add("/admin/blog/articles/{id}", delete(admin_delete))
|
||||
.add("/admin/blog/articles/{id}/publish", post(admin_publish))
|
||||
.add("/admin/blog/articles/{id}/unpublish", post(admin_unpublish))
|
||||
}
|
||||
479
src/controllers/frontend.rs
Normal file
@@ -0,0 +1,479 @@
|
||||
use crate::{
|
||||
controllers::{admin, auth as auth_controller, i18n::current_lang},
|
||||
models::{
|
||||
_entities::{audio_albums, audio_tracks, blog_articles, site_pages},
|
||||
users::{self, LoginParams},
|
||||
},
|
||||
};
|
||||
use axum_extra::extract::cookie::CookieJar;
|
||||
use chrono::Utc;
|
||||
use loco_rs::prelude::*;
|
||||
use sea_orm::{
|
||||
sea_query::Expr, ActiveModelTrait, ColumnTrait, EntityTrait, Order, QueryFilter, QueryOrder,
|
||||
QuerySelect, Set,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use uuid::Uuid;
|
||||
|
||||
const ABOUT_SLUG: &str = "about";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ArticleForm {
|
||||
title: String,
|
||||
content: String,
|
||||
excerpt: Option<String>,
|
||||
published: Option<String>,
|
||||
featured_image_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct AboutForm {
|
||||
title: String,
|
||||
content: String,
|
||||
}
|
||||
|
||||
fn slugify(title: &str) -> String {
|
||||
let mut slug = String::new();
|
||||
let mut last_was_dash = false;
|
||||
|
||||
for ch in title.chars().flat_map(char::to_lowercase) {
|
||||
if ch.is_ascii_alphanumeric() {
|
||||
slug.push(ch);
|
||||
last_was_dash = false;
|
||||
} else if !last_was_dash && !slug.is_empty() {
|
||||
slug.push('-');
|
||||
last_was_dash = true;
|
||||
}
|
||||
}
|
||||
|
||||
let slug = slug.trim_matches('-').to_string();
|
||||
if slug.is_empty() {
|
||||
Uuid::new_v4().to_string()
|
||||
} else {
|
||||
slug
|
||||
}
|
||||
}
|
||||
|
||||
fn published_at_for(published: bool) -> Option<chrono::DateTime<chrono::FixedOffset>> {
|
||||
published.then(|| Utc::now().into())
|
||||
}
|
||||
|
||||
fn is_checked(value: &Option<String>) -> bool {
|
||||
value
|
||||
.as_deref()
|
||||
.is_some_and(|value| value == "on" || value == "true")
|
||||
}
|
||||
|
||||
fn normalize_empty(value: Option<String>) -> Option<String> {
|
||||
value.and_then(|value| {
|
||||
let value = value.trim().to_string();
|
||||
if value.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(value)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async fn about_page(ctx: &AppContext) -> Result<site_pages::Model> {
|
||||
site_pages::Entity::find()
|
||||
.filter(site_pages::Column::Slug.eq(ABOUT_SLUG))
|
||||
.one(&ctx.db)
|
||||
.await?
|
||||
.ok_or_else(|| Error::NotFound)
|
||||
}
|
||||
|
||||
async fn article_by_id(ctx: &AppContext, id: Uuid) -> Result<blog_articles::Model> {
|
||||
blog_articles::Entity::find_by_id(id)
|
||||
.one(&ctx.db)
|
||||
.await?
|
||||
.ok_or_else(|| Error::NotFound)
|
||||
}
|
||||
|
||||
async fn logged_in_admin(ctx: &AppContext, jar: &CookieJar) -> bool {
|
||||
let Some(cookie) = jar.get(auth_controller::AUTH_COOKIE) else {
|
||||
return false;
|
||||
};
|
||||
let Ok(jwt_config) = ctx.config.get_jwt_config() else {
|
||||
return false;
|
||||
};
|
||||
let Ok(claims) = loco_rs::auth::jwt::JWT::new(&jwt_config.secret).validate(cookie.value())
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let Ok(user) = users::Model::find_by_pid(&ctx.db, &claims.claims.pid).await else {
|
||||
return false;
|
||||
};
|
||||
|
||||
admin::is_admin(ctx, &user)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn home(
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
let articles = blog_articles::Entity::find()
|
||||
.filter(blog_articles::Column::Published.eq(true))
|
||||
.order_by_desc(blog_articles::Column::PublishedAt)
|
||||
.limit(5)
|
||||
.all(&ctx.db)
|
||||
.await?;
|
||||
|
||||
// A random published song to suggest on the landing page.
|
||||
let featured_track = audio_tracks::Entity::find()
|
||||
.filter(audio_tracks::Column::Published.eq(true))
|
||||
.order_by(Expr::cust("RANDOM()"), Order::Asc)
|
||||
.one(&ctx.db)
|
||||
.await?;
|
||||
|
||||
// A random published album, never the one the suggested song belongs to.
|
||||
let mut album_query =
|
||||
audio_albums::Entity::find().filter(audio_albums::Column::Published.eq(true));
|
||||
if let Some(album_id) = featured_track.as_ref().and_then(|track| track.album_id) {
|
||||
album_query = album_query.filter(audio_albums::Column::Id.ne(album_id));
|
||||
}
|
||||
let featured_album = album_query
|
||||
.order_by(Expr::cust("RANDOM()"), Order::Asc)
|
||||
.one(&ctx.db)
|
||||
.await?;
|
||||
|
||||
format::view(
|
||||
&v,
|
||||
"home/index.html",
|
||||
json!({
|
||||
"articles": articles,
|
||||
"featured_track": featured_track,
|
||||
"featured_album": featured_album,
|
||||
"logged_in_admin": logged_in_admin(&ctx, &jar).await,
|
||||
"lang": current_lang(&jar),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn about(
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
format::view(
|
||||
&v,
|
||||
"pages/about.html",
|
||||
json!({
|
||||
"page": about_page(&ctx).await?,
|
||||
"logged_in_admin": logged_in_admin(&ctx, &jar).await,
|
||||
"lang": current_lang(&jar),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn blog_index(
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
let articles = blog_articles::Entity::find()
|
||||
.filter(blog_articles::Column::Published.eq(true))
|
||||
.order_by_desc(blog_articles::Column::PublishedAt)
|
||||
.all(&ctx.db)
|
||||
.await?;
|
||||
|
||||
format::view(
|
||||
&v,
|
||||
"blog/index.html",
|
||||
json!({
|
||||
"articles": articles,
|
||||
"logged_in_admin": logged_in_admin(&ctx, &jar).await,
|
||||
"lang": current_lang(&jar),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn blog_show(
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
Path(slug): Path<String>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
let article = blog_articles::Entity::find()
|
||||
.filter(blog_articles::Column::Slug.eq(slug))
|
||||
.filter(blog_articles::Column::Published.eq(true))
|
||||
.one(&ctx.db)
|
||||
.await?
|
||||
.ok_or_else(|| Error::NotFound)?;
|
||||
|
||||
let mut active = article.into_active_model();
|
||||
let next_count = active.view_count.as_ref().to_owned() + 1;
|
||||
active.view_count = Set(next_count);
|
||||
let article = active.update(&ctx.db).await?;
|
||||
|
||||
format::view(
|
||||
&v,
|
||||
"blog/show.html",
|
||||
json!({
|
||||
"article": article,
|
||||
"logged_in_admin": logged_in_admin(&ctx, &jar).await,
|
||||
"lang": current_lang(&jar),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_login_page(
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
if logged_in_admin(&ctx, &jar).await {
|
||||
return format::redirect("/admin/dashboard");
|
||||
}
|
||||
|
||||
format::view(
|
||||
&v,
|
||||
"admin/login.html",
|
||||
json!({
|
||||
"error": null,
|
||||
"logged_in_admin": false,
|
||||
"lang": current_lang(&jar),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_login(
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
State(ctx): State<AppContext>,
|
||||
Form(params): Form<LoginParams>,
|
||||
) -> Result<Response> {
|
||||
let Ok(user) = users::Model::find_by_email(&ctx.db, ¶ms.email).await else {
|
||||
return format::view(
|
||||
&v,
|
||||
"admin/login.html",
|
||||
json!({
|
||||
"error": "Invalid credentials",
|
||||
"logged_in_admin": false,
|
||||
"lang": current_lang(&jar),
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
if !user.verify_password(¶ms.password) || !admin::is_admin(&ctx, &user) {
|
||||
return format::view(
|
||||
&v,
|
||||
"admin/login.html",
|
||||
json!({
|
||||
"error": "Invalid credentials",
|
||||
"logged_in_admin": false,
|
||||
"lang": current_lang(&jar),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
let jwt_secret = ctx.config.get_jwt_config()?;
|
||||
let token = user
|
||||
.generate_jwt(&jwt_secret.secret, jwt_secret.expiration)
|
||||
.or_else(|_| unauthorized("unauthorized!"))?;
|
||||
|
||||
format::render()
|
||||
.cookies(&[auth_controller::auth_cookie(&token, jwt_secret.expiration)])?
|
||||
.redirect("/admin/dashboard")
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_logout() -> Result<Response> {
|
||||
format::render()
|
||||
.cookies(&[auth_controller::clear_auth_cookie()])?
|
||||
.redirect("/admin/login")
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_home(
|
||||
auth: auth::JWT,
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
let admin_user = admin::current_admin(auth, &ctx).await?;
|
||||
format::view(
|
||||
&v,
|
||||
"admin/index.html",
|
||||
json!({ "admin": admin_user, "lang": current_lang(&jar) }),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_about(
|
||||
auth: auth::JWT,
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
format::view(
|
||||
&v,
|
||||
"admin/about.html",
|
||||
json!({ "page": about_page(&ctx).await?, "lang": current_lang(&jar) }),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_about_update(
|
||||
auth: auth::JWT,
|
||||
State(ctx): State<AppContext>,
|
||||
Form(params): Form<AboutForm>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
let mut page = about_page(&ctx).await?.into_active_model();
|
||||
page.title = Set(params.title);
|
||||
page.content = Set(params.content);
|
||||
page.update(&ctx.db).await?;
|
||||
format::redirect("/admin/about")
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_articles(
|
||||
auth: auth::JWT,
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
let articles = blog_articles::Entity::find()
|
||||
.order_by_desc(blog_articles::Column::CreatedAt)
|
||||
.all(&ctx.db)
|
||||
.await?;
|
||||
format::view(
|
||||
&v,
|
||||
"admin/blog/index.html",
|
||||
json!({ "articles": articles, "lang": current_lang(&jar) }),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_article_new(
|
||||
auth: auth::JWT,
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
format::view(
|
||||
&v,
|
||||
"admin/blog/new.html",
|
||||
json!({ "lang": current_lang(&jar) }),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_article_create(
|
||||
auth: auth::JWT,
|
||||
State(ctx): State<AppContext>,
|
||||
Form(params): Form<ArticleForm>,
|
||||
) -> Result<Response> {
|
||||
let admin_user = admin::current_admin(auth, &ctx).await?;
|
||||
let published = is_checked(¶ms.published);
|
||||
|
||||
blog_articles::ActiveModel {
|
||||
id: Set(Uuid::new_v4()),
|
||||
title: Set(params.title.clone()),
|
||||
slug: Set(slugify(¶ms.title)),
|
||||
content: Set(params.content),
|
||||
excerpt: Set(normalize_empty(params.excerpt)),
|
||||
published: Set(published),
|
||||
author_id: Set(admin_user.id),
|
||||
featured_image_id: Set(normalize_empty(params.featured_image_id)),
|
||||
view_count: Set(0),
|
||||
published_at: Set(published_at_for(published)),
|
||||
..Default::default()
|
||||
}
|
||||
.insert(&ctx.db)
|
||||
.await?;
|
||||
|
||||
format::redirect("/admin/blog/articles")
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_article_edit(
|
||||
auth: auth::JWT,
|
||||
jar: CookieJar,
|
||||
ViewEngine(v): ViewEngine<TeraView>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
format::view(
|
||||
&v,
|
||||
"admin/blog/edit.html",
|
||||
json!({ "article": article_by_id(&ctx, id).await?, "lang": current_lang(&jar) }),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_article_update(
|
||||
auth: auth::JWT,
|
||||
Path(id): Path<Uuid>,
|
||||
State(ctx): State<AppContext>,
|
||||
Form(params): Form<ArticleForm>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
let existing = article_by_id(&ctx, id).await?;
|
||||
let was_published = existing.published;
|
||||
let published = is_checked(¶ms.published);
|
||||
|
||||
let mut article = existing.into_active_model();
|
||||
article.title = Set(params.title.clone());
|
||||
article.slug = Set(slugify(¶ms.title));
|
||||
article.content = Set(params.content);
|
||||
article.excerpt = Set(normalize_empty(params.excerpt));
|
||||
article.published = Set(published);
|
||||
article.featured_image_id = Set(normalize_empty(params.featured_image_id));
|
||||
if published && !was_published {
|
||||
article.published_at = Set(published_at_for(true));
|
||||
} else if !published {
|
||||
article.published_at = Set(None);
|
||||
}
|
||||
article.update(&ctx.db).await?;
|
||||
|
||||
format::redirect("/admin/blog/articles")
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn admin_article_delete(
|
||||
auth: auth::JWT,
|
||||
Path(id): Path<Uuid>,
|
||||
State(ctx): State<AppContext>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
article_by_id(&ctx, id).await?.delete(&ctx.db).await?;
|
||||
format::redirect("/admin/blog/articles")
|
||||
}
|
||||
|
||||
pub fn routes() -> Routes {
|
||||
Routes::new()
|
||||
.add("/", get(home))
|
||||
.add("/about", get(about))
|
||||
.add("/blog", get(blog_index))
|
||||
.add("/blog/{slug}", get(blog_show))
|
||||
.add("/admin/login", get(admin_login_page))
|
||||
.add("/admin/login", post(admin_login))
|
||||
.add("/admin/logout", post(admin_logout))
|
||||
.add("/admin", get(admin_login_page))
|
||||
.add("/admin/dashboard", get(admin_home))
|
||||
.add("/admin/about", get(admin_about))
|
||||
.add("/admin/about", post(admin_about_update))
|
||||
.add("/admin/blog/articles", get(admin_articles))
|
||||
.add("/admin/blog/articles/new", get(admin_article_new))
|
||||
.add("/admin/blog/articles", post(admin_article_create))
|
||||
.add("/admin/blog/articles/{id}/edit", get(admin_article_edit))
|
||||
.add("/admin/blog/articles/{id}", post(admin_article_update))
|
||||
.add(
|
||||
"/admin/blog/articles/{id}/delete",
|
||||
post(admin_article_delete),
|
||||
)
|
||||
}
|
||||
63
src/controllers/i18n.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use axum::{
|
||||
http::{header, HeaderMap},
|
||||
response::Redirect,
|
||||
};
|
||||
use loco_rs::prelude::*;
|
||||
use serde::Deserialize;
|
||||
|
||||
pub const LANG_COOKIE: &str = "lang";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct LangForm {
|
||||
pub lang: String,
|
||||
}
|
||||
|
||||
pub fn current_lang(jar: &axum_extra::extract::cookie::CookieJar) -> String {
|
||||
match jar
|
||||
.get(LANG_COOKIE)
|
||||
.map(|cookie| cookie.value().to_string())
|
||||
{
|
||||
Some(ref lang) if lang == "en" => "en".to_string(),
|
||||
_ => "sk".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn set_lang(headers: HeaderMap, Form(form): Form<LangForm>) -> Result<Response> {
|
||||
let lang = if form.lang == "en" { "en" } else { "sk" };
|
||||
let cookie = format!("{LANG_COOKIE}={lang}; Path=/; Max-Age=31536000; SameSite=Lax");
|
||||
|
||||
Ok((
|
||||
[(header::SET_COOKIE, cookie)],
|
||||
Redirect::to(&back_path(&headers)),
|
||||
)
|
||||
.into_response())
|
||||
}
|
||||
|
||||
fn back_path(headers: &HeaderMap) -> String {
|
||||
let raw = headers
|
||||
.get(header::REFERER)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.unwrap_or("/");
|
||||
|
||||
if raw.starts_with('/') {
|
||||
return raw.to_string();
|
||||
}
|
||||
|
||||
if let Some(after_scheme) = raw.split_once("://").map(|(_, rest)| rest) {
|
||||
if let Some(path_start) = after_scheme.find('/') {
|
||||
let path = &after_scheme[path_start..];
|
||||
return if path.starts_with('/') {
|
||||
path.to_string()
|
||||
} else {
|
||||
"/".to_string()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
"/".to_string()
|
||||
}
|
||||
|
||||
pub fn routes() -> Routes {
|
||||
Routes::new().add("/lang", post(set_lang))
|
||||
}
|
||||
1141
src/controllers/media.rs
Normal file
7
src/controllers/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
pub mod admin;
|
||||
pub mod auth;
|
||||
pub mod blog;
|
||||
pub mod frontend;
|
||||
pub mod i18n;
|
||||
pub mod media;
|
||||
pub mod pages;
|
||||
86
src/controllers/pages.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
use crate::{controllers::admin, models::_entities::site_pages};
|
||||
use loco_rs::prelude::*;
|
||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, Set};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
const ABOUT_SLUG: &str = "about";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct AboutParams {
|
||||
title: String,
|
||||
content: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct PageResponse {
|
||||
id: Uuid,
|
||||
slug: String,
|
||||
title: String,
|
||||
content: String,
|
||||
updated_at: chrono::DateTime<chrono::FixedOffset>,
|
||||
}
|
||||
|
||||
impl From<site_pages::Model> for PageResponse {
|
||||
fn from(page: site_pages::Model) -> Self {
|
||||
Self {
|
||||
id: page.id,
|
||||
slug: page.slug,
|
||||
title: page.title,
|
||||
content: page.content,
|
||||
updated_at: page.updated_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn find_about(ctx: &AppContext) -> Result<site_pages::Model> {
|
||||
site_pages::Entity::find()
|
||||
.filter(site_pages::Column::Slug.eq(ABOUT_SLUG))
|
||||
.one(&ctx.db)
|
||||
.await?
|
||||
.ok_or_else(|| Error::NotFound)
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn about(State(ctx): State<AppContext>) -> Result<Response> {
|
||||
format::json(PageResponse::from(find_about(&ctx).await?))
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
async fn update_about(
|
||||
auth: auth::JWT,
|
||||
State(ctx): State<AppContext>,
|
||||
Json(params): Json<AboutParams>,
|
||||
) -> Result<Response> {
|
||||
admin::current_admin(auth, &ctx).await?;
|
||||
|
||||
let page = match find_about(&ctx).await {
|
||||
Ok(page) => {
|
||||
let mut page = page.into_active_model();
|
||||
page.title = Set(params.title);
|
||||
page.content = Set(params.content);
|
||||
page.update(&ctx.db).await?
|
||||
}
|
||||
Err(Error::NotFound) => {
|
||||
site_pages::ActiveModel {
|
||||
id: Set(Uuid::new_v4()),
|
||||
slug: Set(ABOUT_SLUG.to_string()),
|
||||
title: Set(params.title),
|
||||
content: Set(params.content),
|
||||
..Default::default()
|
||||
}
|
||||
.insert(&ctx.db)
|
||||
.await?
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
|
||||
format::json(PageResponse::from(page))
|
||||
}
|
||||
|
||||
pub fn routes() -> Routes {
|
||||
Routes::new()
|
||||
.prefix("/api")
|
||||
.add("/about", get(about))
|
||||
.add("/admin/about", put(update_about))
|
||||
}
|
||||
1
src/data/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
17
src/fixtures/users.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- id: 1
|
||||
pid: 11111111-1111-1111-1111-111111111111
|
||||
email: user1@example.com
|
||||
password: "$argon2id$v=19$m=19456,t=2,p=1$ETQBx4rTgNAZhSaeYZKOZg$eYTdH26CRT6nUJtacLDEboP0li6xUwUF/q5nSlQ8uuc"
|
||||
api_key: lo-95ec80d7-cb60-4b70-9b4b-9ef74cb88758
|
||||
name: user1
|
||||
created_at: "2023-11-12T12:34:56.789Z"
|
||||
updated_at: "2023-11-12T12:34:56.789Z"
|
||||
- id: 2
|
||||
pid: 22222222-2222-2222-2222-222222222222
|
||||
email: user2@example.com
|
||||
password: "$argon2id$v=19$m=19456,t=2,p=1$ETQBx4rTgNAZhSaeYZKOZg$eYTdH26CRT6nUJtacLDEboP0li6xUwUF/q5nSlQ8uuc"
|
||||
api_key: lo-153561ca-fa84-4e1b-813a-c62526d0a77e
|
||||
name: user2
|
||||
created_at: "2023-11-12T12:34:56.789Z"
|
||||
updated_at: "2023-11-12T12:34:56.789Z"
|
||||
36
src/initializers/admin_seeder.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use async_trait::async_trait;
|
||||
use loco_rs::prelude::*;
|
||||
|
||||
use crate::models::users::{self, RegisterParams};
|
||||
|
||||
pub struct AdminSeeder;
|
||||
|
||||
#[async_trait]
|
||||
impl Initializer for AdminSeeder {
|
||||
fn name(&self) -> String {
|
||||
"admin-seeder".to_string()
|
||||
}
|
||||
|
||||
async fn before_run(&self, ctx: &AppContext) -> Result<()> {
|
||||
let email = std::env::var("ADMIN_EMAIL").unwrap_or_default();
|
||||
let password = std::env::var("ADMIN_PASSWORD").unwrap_or_default();
|
||||
let name = std::env::var("ADMIN_NAME").unwrap_or_else(|_| "Admin".to_string());
|
||||
|
||||
if email.is_empty() || password.is_empty() {
|
||||
tracing::warn!("ADMIN_EMAIL / ADMIN_PASSWORD not set in .env; admin not seeded");
|
||||
} else if users::Model::find_by_email(&ctx.db, &email).await.is_err() {
|
||||
users::Model::create_with_password(
|
||||
&ctx.db,
|
||||
&RegisterParams {
|
||||
email: email.clone(),
|
||||
password,
|
||||
name,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
tracing::info!(admin = %email, "admin user seeded");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
2
src/initializers/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod admin_seeder;
|
||||
pub mod view_engine;
|
||||
46
src/initializers/view_engine.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use async_trait::async_trait;
|
||||
use axum::{Extension, Router as AxumRouter};
|
||||
use fluent_templates::{ArcLoader, FluentLoader};
|
||||
use loco_rs::{
|
||||
app::{AppContext, Initializer},
|
||||
controller::views::{engines, ViewEngine},
|
||||
Error, Result,
|
||||
};
|
||||
use tracing::info;
|
||||
|
||||
const I18N_DIR: &str = "assets/i18n";
|
||||
// Kept outside `I18N_DIR`: fluent-templates >=0.13 scans top-level *.ftl files
|
||||
// in that dir as locales, and "shared" parses as a langid, so a shared.ftl
|
||||
// living there would be loaded twice and fail with a duplicate-resource error.
|
||||
const I18N_SHARED: &str = "assets/i18n_shared/shared.ftl";
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
pub struct ViewEngineInitializer;
|
||||
|
||||
#[async_trait]
|
||||
impl Initializer for ViewEngineInitializer {
|
||||
fn name(&self) -> String {
|
||||
"view-engine".to_string()
|
||||
}
|
||||
|
||||
async fn after_routes(&self, router: AxumRouter, _ctx: &AppContext) -> Result<AxumRouter> {
|
||||
let tera_engine = if std::path::Path::new(I18N_DIR).exists() {
|
||||
let arc = std::sync::Arc::new(
|
||||
ArcLoader::builder(&I18N_DIR, unic_langid::langid!("sk"))
|
||||
.shared_resources(Some(&[I18N_SHARED.into()]))
|
||||
.customize(|bundle| bundle.set_use_isolating(false))
|
||||
.build()
|
||||
.map_err(|e| Error::string(&e.to_string()))?,
|
||||
);
|
||||
info!("locales loaded");
|
||||
|
||||
engines::TeraView::build()?.post_process(move |tera| {
|
||||
tera.register_function("t", FluentLoader::new(arc.clone()));
|
||||
Ok(())
|
||||
})?
|
||||
} else {
|
||||
engines::TeraView::build()?
|
||||
};
|
||||
|
||||
Ok(router.layer(Extension(ViewEngine::from(tera_engine))))
|
||||
}
|
||||
}
|
||||
9
src/lib.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
pub mod app;
|
||||
pub mod controllers;
|
||||
pub mod data;
|
||||
pub mod initializers;
|
||||
pub mod mailers;
|
||||
pub mod models;
|
||||
pub mod tasks;
|
||||
pub mod views;
|
||||
pub mod workers;
|
||||
90
src/mailers/auth.rs
Normal file
@@ -0,0 +1,90 @@
|
||||
// auth mailer
|
||||
#![allow(non_upper_case_globals)]
|
||||
|
||||
use loco_rs::prelude::*;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::models::users;
|
||||
|
||||
static welcome: Dir<'_> = include_dir!("src/mailers/auth/welcome");
|
||||
static forgot: Dir<'_> = include_dir!("src/mailers/auth/forgot");
|
||||
static magic_link: Dir<'_> = include_dir!("src/mailers/auth/magic_link");
|
||||
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
pub struct AuthMailer {}
|
||||
impl Mailer for AuthMailer {}
|
||||
impl AuthMailer {
|
||||
/// Sending welcome email the the given user
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When email sending is failed
|
||||
pub async fn send_welcome(ctx: &AppContext, user: &users::Model) -> Result<()> {
|
||||
Self::mail_template(
|
||||
ctx,
|
||||
&welcome,
|
||||
mailer::Args {
|
||||
to: user.email.to_string(),
|
||||
locals: json!({
|
||||
"name": user.name,
|
||||
"verifyToken": user.email_verification_token,
|
||||
"domain": ctx.config.server.full_url()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sending forgot password email
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When email sending is failed
|
||||
pub async fn forgot_password(ctx: &AppContext, user: &users::Model) -> Result<()> {
|
||||
Self::mail_template(
|
||||
ctx,
|
||||
&forgot,
|
||||
mailer::Args {
|
||||
to: user.email.to_string(),
|
||||
locals: json!({
|
||||
"name": user.name,
|
||||
"resetToken": user.reset_token,
|
||||
"domain": ctx.config.server.full_url()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sends a magic link authentication email to the user.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When email sending is failed
|
||||
pub async fn send_magic_link(ctx: &AppContext, user: &users::Model) -> Result<()> {
|
||||
Self::mail_template(
|
||||
ctx,
|
||||
&magic_link,
|
||||
mailer::Args {
|
||||
to: user.email.to_string(),
|
||||
locals: json!({
|
||||
"name": user.name,
|
||||
"token": user.magic_link_token.clone().ok_or_else(|| Error::string(
|
||||
"the user model not contains magic link token",
|
||||
))?,
|
||||
"host": ctx.config.server.full_url()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
11
src/mailers/auth/forgot/html.t
Normal file
@@ -0,0 +1,11 @@
|
||||
;<html>
|
||||
|
||||
<body>
|
||||
Hey {{name}},
|
||||
Forgot your password? No worries! You can reset it by clicking the link below:
|
||||
<a href="http://{{domain}}/reset#{{resetToken}}">Reset Your Password</a>
|
||||
If you didn't request a password reset, please ignore this email.
|
||||
Best regards,<br>The Loco Team</br>
|
||||
</body>
|
||||
|
||||
</html>
|
||||