fix: technical debts left by the Sites, Authors and SEO slices, plus backend support for the new Sites and Authors pagination

This commit is contained in:
Florian Sylvain committed 2026-10-19 00:25:31 +02:00
1 parent 9f4ce426a8
commit daf3594316
86 files changed
+4223 -1485

No files matched your search

+75 -267
View File
@@ -1,41 +1,34 @@
<script setup lang="ts">
import { t } from '@/i18n'
import { computed, nextTick, onMounted, ref, watch } from 'vue'
import { computed, nextTick, ref } from 'vue'
import { createReusableTemplate, useMediaQuery } from '@vueuse/core'
import DirectoryField from '@/components/DirectoryField.vue'
import DirectoryPanel from '@/components/DirectoryPanel.vue'
import FallbackChip from '@/components/FallbackChip.vue'
import MediaField from '@/components/MediaField.vue'
import SearchPreview from '@/components/SearchPreview.vue'
import SeoDisclosure from '@/components/SeoDisclosure.vue'
import SeoAdvancedSection from '@/components/SeoAdvancedSection.vue'
import SeoSocialSection from '@/components/SeoSocialSection.vue'
import SlugField from '@/components/SlugField.vue'
import SocialCardPreview from '@/components/SocialCardPreview.vue'
import SoftCounter from '@/components/SoftCounter.vue'
import SuggestionList from '@/components/SuggestionList.vue'
import type { SeoCheckPhase } from '@/composables/useSeoCheck'
import type { MediaItem } from '@/composables/useMedia'
import { useMediaNames } from '@/composables/useMediaNames'
import { useSeoPanelCanonical } from '@/composables/useSeoPanelCanonical'
import { useSeoPanelImages } from '@/composables/useSeoPanelImages'
import { useSeoPanelSlug } from '@/composables/useSeoPanelSlug'
import type { Site } from '@/composables/useSites'
import {
SEO_LIMITS,
canonicalIsValid,
charCount,
normalizeSlug,
typedSlug,
type ArticleSeo,
} from '@/lib/articleSeo'
import { slugify } from '@/lib/directory'
import { SEO_LIMITS, charCount, type ArticleSeo } from '@/lib/articleSeo'
import { chipLabel, descriptionChip } from '@/lib/seoCopy'
import type { DirectoryNotice } from '@/lib/directoryTypes'
import { areaUi, fieldUi } from '@/lib/seoFieldUi'
import {
DESCRIPTION_RANGE,
TITLE_RANGE,
hasSocialOverrides,
siteDisplayName,
previewDescription,
previewDescriptionSource,
socialImageSource,
type PreviewDevice,
type SeoPreviewInput,
} from '@/lib/seoPreview'
@@ -86,18 +79,9 @@ const [DefinePreviews, Previews] = createReusableTemplate()
const [DefinePreviewButton, PreviewButton] = createReusableTemplate()
const isDesktop = useMediaQuery(DESKTOP_QUERY)
const names = useMediaNames()
const layout = ref<HTMLElement | null>(null)
const focusTarget = ref<SeoFocus | null>(props.focus)
const device = ref<PreviewDevice>('desktop')
const socialOpen = ref(false)
const advancedOpen = ref(props.canonicalRejected)
const canonicalMessage = ref('')
const generatedSlug = computed(() => slugify(props.articleTitle, SEO_LIMITS.slug))
const slugManual = ref(
props.modelValue.slug !== '' && props.modelValue.slug !== generatedSlug.value,
)
const slugText = ref(props.modelValue.slug || generatedSlug.value)
const seo = computed(() => props.modelValue)
const siteName = computed(() => siteDisplayName(props.site))
@@ -107,66 +91,53 @@ const previewInput = computed<SeoPreviewInput>(() => ({
body: props.body,
site: props.site,
}))
const displaySlug = computed(() => (slugManual.value ? slugText.value : generatedSlug.value))
const slugMode = computed(() => {
if (slugManual.value) {
return 'manual' as const
}
return generatedSlug.value ? ('auto' as const) : ('empty' as const)
})
const siteImageId = computed(() => props.site?.default_social_image_id ?? null)
const siteImageName = computed(() => {
const id = siteImageId.value
if (id === null) {
return ''
}
return names.itemOf(id)?.filename ?? t('Image #{0}', [id])
})
const coverItem = computed(() => names.itemOf(seo.value.cover_image_id))
const socialItem = computed(() => names.itemOf(seo.value.social_image_id))
const cardSource = computed(() => socialImageSource(seo.value, siteImageId.value !== null))
const cardImageItem = computed(() => {
const items = {
social: socialItem.value,
cover: coverItem.value,
site: names.itemOf(siteImageId.value),
none: null,
}
return items[cardSource.value]
})
const cardImageName = computed(() => {
const labels = {
social: socialItem.value?.filename ?? t('Image #{0}', [seo.value.social_image_id ?? 0]),
cover: coverItem.value?.filename ?? t('Image #{0}', [seo.value.cover_image_id ?? 0]),
site: siteImageName.value,
none: '',
}
return labels[cardSource.value]
function update(patch: Partial<ArticleSeo>, immediate = false) {
emit('update:modelValue', { ...props.modelValue, ...patch })
emit('check', immediate)
}
const {
siteImageId,
siteImageName,
coverItem,
socialItem,
cardSource,
cardImageItem,
cardImageName,
remember,
} = useSeoPanelImages(seo, () => props.site)
const {
displaySlug,
slugMode,
slugSuggestion,
slugError,
slugUrl,
typeSlug,
unlockSlug,
resetSlug,
useSuggestedSlug,
checkSlug,
} = useSeoPanelSlug({
seo,
articleTitle: () => props.articleTitle,
savedSlug: () => props.savedSlug,
site: () => props.site,
siteName,
slugTakenOnSave: () => props.slugTakenOnSave,
slugVerdict: () => props.slugVerdict,
checkedSlug: () => props.checkedSlug,
update,
requestCheck: () => emit('check', true),
})
const slugTaken = computed(() => {
if (props.slugTakenOnSave !== null && props.slugTakenOnSave === seo.value.slug) {
return true
}
const verdict = props.slugVerdict
return (
verdict !== null &&
!verdict.available &&
props.checkedSlug !== undefined &&
props.checkedSlug === seo.value.slug
)
})
const slugSuggestion = computed(() =>
slugTaken.value && props.checkedSlug === seo.value.slug
? (props.slugVerdict?.suggestion ?? '')
: '',
)
const slugError = computed(() =>
slugTaken.value
? t('The slug "{0}" is already used on {1}.', [displaySlug.value, siteName.value])
: '',
)
const slugUrl = computed(() => `${props.site?.base_url ?? ''}/${displaySlug.value}`)
const { advancedOpen, advancedSummary, canonicalError, typeCanonical, canonicalBlocked } =
useSeoPanelCanonical({
seo,
rejected: () => props.canonicalRejected,
update,
})
const descriptionPlaceholder = computed(() => previewDescription(previewInput.value))
const descriptionChipLabel = computed(() =>
@@ -184,40 +155,11 @@ const coverHelp = computed(() => {
? t('Using the site social image ({0}).', [siteImageName.value])
: t('Using the site social image.')
})
const coverPicker = computed(() =>
pickerCopy(t('Choose a cover image'), t('The cover for this article.')),
)
const socialPicker = computed(() =>
pickerCopy(t('Choose a social image'), t('The image shown when this article is shared.')),
)
const customised = computed(() => hasSocialOverrides(seo.value))
const socialSummary = computed(() => {
if (customised.value) {
return t('Customised')
}
return socialOpen.value ? '' : t('Uses the meta values')
})
const advancedSummary = computed(() => {
if (advancedOpen.value) {
return ''
}
return seo.value.canonical_url ? t('Canonical URL set') : t('Canonical URL: automatic')
})
const canonicalError = computed(() =>
canonicalMessage.value || props.canonicalRejected
? t('Enter a full address starting with https://')
: '',
)
const canonicalPlaceholder = computed(() => slugUrl.value)
function pickerCopy(title: string, description: string) {
return { title, description, confirmLabel: t('Use image') }
}
function update(patch: Partial<ArticleSeo>, immediate = false) {
emit('update:modelValue', { ...props.modelValue, ...patch })
emit('check', immediate)
}
const coverPicker = computed(() => ({
title: t('Choose a cover image'),
description: t('The cover for this article.'),
confirmLabel: t('Use image'),
}))
function typeText(
key:
@@ -232,56 +174,6 @@ function typeText(
update({ [key]: value })
}
function typeCanonical(value: string) {
canonicalMessage.value = ''
update({ canonical_url: value })
}
function canonicalBlocked() {
if (canonicalIsValid(seo.value.canonical_url)) {
return false
}
canonicalMessage.value = 'invalid'
advancedOpen.value = true
return true
}
function checkCanonical() {
canonicalBlocked()
}
function autoSlug() {
return generatedSlug.value === props.savedSlug ? props.savedSlug : ''
}
function unlockSlug() {
slugManual.value = true
slugText.value = generatedSlug.value
}
function typeSlug(value: string) {
slugText.value = typedSlug(value)
update({ slug: normalizeSlug(slugText.value) })
}
function resetSlug() {
slugManual.value = false
slugText.value = generatedSlug.value
update({ slug: autoSlug() }, true)
}
function useSuggestedSlug(suggestion: string) {
slugManual.value = true
slugText.value = suggestion
update({ slug: suggestion }, true)
}
function checkSlug() {
if (slugManual.value) {
emit('check', true)
}
}
function setCover(id: number | null) {
update({ cover_image_id: id }, true)
}
@@ -294,12 +186,6 @@ function setNoindex(value: boolean) {
update({ noindex: value }, true)
}
function remember(item: MediaItem | null) {
if (item) {
names.remember(item)
}
}
function goTo(field: SuggestionField) {
if (!PANEL_FIELDS.includes(field)) {
emit('go', field)
@@ -317,26 +203,6 @@ function submit() {
emit('submit')
}
}
watch(
() => props.canonicalRejected,
(rejected) => {
if (rejected) {
advancedOpen.value = true
}
},
)
onMounted(() => {
names.resolve([siteImageId.value, seo.value.cover_image_id, seo.value.social_image_id])
})
const DISABLED_FIELD = 'disabled:bg-elevated disabled:opacity-100'
const fieldUi = { base: `h-11 text-lg text-ellipsis md:h-10 md:text-sm ${DISABLED_FIELD}` }
const monoFieldUi = {
base: `h-11 font-mono text-base text-ellipsis md:h-10 md:text-code ${DISABLED_FIELD}`,
}
const areaUi = { base: `min-h-30 text-lg md:min-h-24 md:text-sm ${DISABLED_FIELD}` }
</script>
<template>
@@ -552,84 +418,26 @@ const areaUi = { base: `min-h-30 text-lg md:min-h-24 md:text-sm ${DISABLED_FIELD
</DirectoryField>
</div>
<SeoDisclosure
v-model:open="socialOpen"
:title="t('Social sharing')"
:tag="t('Optional')"
:summary="socialSummary"
>
<div class="flex flex-col gap-1.5">
<DirectoryField :label="t('Social title')" optional>
<UInput
:model-value="seo.social_title"
:placeholder="seo.seo_title || articleTitle"
:maxlength="SEO_LIMITS.social_title"
autocomplete="off"
class="w-full"
:ui="fieldUi"
@update:model-value="typeText('social_title', String($event))"
/>
</DirectoryField>
<FallbackChip v-if="!seo.social_title" :label="chipLabel('meta_title')" />
</div>
<div class="flex flex-col gap-1.5">
<DirectoryField :label="t('Social description')" optional>
<UTextarea
:model-value="seo.social_description"
:placeholder="descriptionPlaceholder"
:maxlength="SEO_LIMITS.social_description"
:rows="3"
class="w-full"
:ui="areaUi"
@update:model-value="typeText('social_description', String($event))"
/>
</DirectoryField>
<FallbackChip
v-if="!seo.social_description"
:label="chipLabel('meta_description')"
/>
</div>
<MediaField
:model-value="seo.social_image_id"
:item="socialItem"
:label="t('Social image')"
:help="seo.social_image_id === null ? t('Using the cover image.') : ''"
:picker="socialPicker"
:disabled="saving"
@update:item="remember"
@update:model-value="setSocialImage"
/>
</SeoDisclosure>
<SeoSocialSection
:seo="seo"
:article-title="articleTitle"
:description-placeholder="descriptionPlaceholder"
:social-item="socialItem"
:saving="saving"
@type="typeText"
@remember="remember"
@image="setSocialImage"
/>
<SeoDisclosure
<SeoAdvancedSection
v-model:open="advancedOpen"
:title="t('Advanced')"
:canonical-url="seo.canonical_url"
:placeholder="slugUrl"
:summary="advancedSummary"
>
<div class="flex flex-col gap-1.5">
<DirectoryField
:label="t('Canonical URL')"
optional
:error="canonicalError"
:help="t('Only change this if the same content lives at another address.')"
>
<UInput
:model-value="seo.canonical_url"
:placeholder="canonicalPlaceholder"
:maxlength="SEO_LIMITS.canonical_url"
:color="canonicalError ? 'error' : undefined"
:aria-invalid="canonicalError ? 'true' : undefined"
inputmode="url"
autocomplete="off"
class="w-full"
:ui="monoFieldUi"
@update:model-value="typeCanonical(String($event))"
@focusout="checkCanonical"
/>
</DirectoryField>
<FallbackChip v-if="!seo.canonical_url" :label="chipLabel('canonical')" />
</div>
</SeoDisclosure>
:error="canonicalError"
@type="typeCanonical"
@leave="canonicalBlocked"
/>
<USwitch
:model-value="seo.noindex"