PR CI / ledger (pull_request) Successful in 4s
PR CI / flow (pull_request) Successful in 4s
PR CI / test (stable) (pull_request) Successful in 45s
PR CI / ui (pull_request) Successful in 48s
PR CI / test (lowest) (pull_request) Successful in 50s
PR CI / security (pull_request) Successful in 54s
PR CI / pr-ci (pull_request) Successful in 2s
PR CI / release-automerge (pull_request) Successful in 3s
86 lines
4.5 KiB
Vue
86 lines
4.5 KiB
Vue
<script setup lang="ts">
|
|
import { boot, useForm } from '../api';
|
|
import Link from '../components/Link.vue';
|
|
import { t } from '../i18n';
|
|
import { flash, navigate } from '../state';
|
|
|
|
const props = defineProps<{ post: Record<string, any> | null; categories: string[]; known_tags: string[] }>();
|
|
|
|
const post = props.post;
|
|
const form = useForm({
|
|
title: post?.title ?? '', slug: post?.slug ?? '', excerpt: post?.excerpt ?? '', body: post?.body ?? '',
|
|
cover_image: post?.cover_image ?? '', category: post?.category ?? '', tags: (post?.tags ?? []) as string[],
|
|
is_featured: post?.is_featured ?? false, is_published: post?.is_published ?? false, published_at: post?.published_at ?? '',
|
|
});
|
|
// Tags are typed as one comma separated line.
|
|
let tagLine = (post?.tags ?? []).join(', ');
|
|
|
|
async function submit(): Promise<void> {
|
|
form.values.tags = tagLine.split(',').map((tag: string) => tag.trim()).filter(Boolean);
|
|
const saved = post
|
|
? await form.send('put', `${boot.base}/posts/${post.id}`)
|
|
: await form.send('post', `${boot.base}/posts`);
|
|
|
|
if (saved) {
|
|
flash(t(post ? 'Saved.' : 'Created.'));
|
|
void navigate(`${boot.base}/posts`);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="mb-6 flex items-center justify-between gap-3">
|
|
<h1 class="font-display text-2xl font-bold">{{ post ? post.title : t('New post') }}</h1>
|
|
<Link :href="boot.base + '/posts'" class="m-btn m-btn-secondary">{{ t('Back') }}</Link>
|
|
</div>
|
|
<form class="m-card max-w-3xl space-y-5 p-5" @submit.prevent="submit">
|
|
<div>
|
|
<label for="title" class="m-label">{{ t('Title') }}</label>
|
|
<input id="title" v-model="form.values.title" required maxlength="255" class="m-input" />
|
|
<p v-if="form.errors.title" class="m-error">{{ form.errors.title }}</p>
|
|
</div>
|
|
<div class="grid gap-5 sm:grid-cols-2">
|
|
<div>
|
|
<label for="slug" class="m-label">{{ t('Address (slug)') }}</label>
|
|
<input id="slug" v-model="form.values.slug" maxlength="255" class="m-input" />
|
|
<p v-if="form.errors.slug" class="m-error">{{ form.errors.slug }}</p>
|
|
</div>
|
|
<div>
|
|
<label for="category" class="m-label">{{ t('Category') }}</label>
|
|
<input id="category" v-model="form.values.category" list="categories" maxlength="60" class="m-input" />
|
|
<datalist id="categories"><option v-for="category in categories" :key="category" :value="category" /></datalist>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label for="excerpt" class="m-label">{{ t('Summary') }}</label>
|
|
<textarea id="excerpt" v-model="form.values.excerpt" rows="2" maxlength="500" class="m-input" />
|
|
<p v-if="form.errors.excerpt" class="m-error">{{ form.errors.excerpt }}</p>
|
|
</div>
|
|
<div>
|
|
<label for="body" class="m-label">{{ t('Text (Markdown)') }}</label>
|
|
<textarea id="body" v-model="form.values.body" rows="14" required class="m-input font-mono" />
|
|
<p v-if="form.errors.body" class="m-error">{{ form.errors.body }}</p>
|
|
</div>
|
|
<div class="grid gap-5 sm:grid-cols-2">
|
|
<div>
|
|
<label for="cover" class="m-label">{{ t('Cover image') }}</label>
|
|
<input id="cover" v-model="form.values.cover_image" maxlength="2048" class="m-input" />
|
|
</div>
|
|
<div>
|
|
<label for="tags" class="m-label">{{ t('Tags (comma separated)') }}</label>
|
|
<input id="tags" v-model="tagLine" list="known-tags" class="m-input" />
|
|
<datalist id="known-tags"><option v-for="tag in known_tags" :key="tag" :value="tag" /></datalist>
|
|
</div>
|
|
</div>
|
|
<div class="flex flex-wrap items-center gap-6">
|
|
<label class="flex items-center gap-2 text-sm"><input v-model="form.values.is_featured" type="checkbox" /> {{ t('Featured') }}</label>
|
|
<label v-if="boot.permissions.includes('posts.publish')" class="flex items-center gap-2 text-sm"><input v-model="form.values.is_published" type="checkbox" /> {{ t('Publish') }}</label>
|
|
<div v-if="form.values.is_published">
|
|
<label for="at" class="m-label">{{ t('Publish at') }}</label>
|
|
<input id="at" v-model="form.values.published_at" type="datetime-local" class="m-input" />
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="m-btn m-btn-primary" :disabled="form.busy">{{ form.busy ? t('Saving…') : t('Save') }}</button>
|
|
</form>
|
|
</template>
|