Add tag command

This commit is contained in:
Christoph Hagen
2024-12-14 19:02:01 +01:00
parent cdaaa36303
commit 657f8c4ef4
8 changed files with 77 additions and 14 deletions

View File

@ -252,9 +252,8 @@ final class PageContentParser {
return handleSvg(arguments, markdown: markdown)
case .audioPlayer:
return audioPlayer.process(arguments, markdown: markdown)
default:
results.invalid(command: nil, markdown)
return ""
case .tagLink:
return handleTagLink(arguments, markdown: markdown)
}
}
@ -439,6 +438,45 @@ final class PageContentParser {
.content
}
/**
Format: `![tag](<tagId>)`
*/
private func handleTagLink(_ arguments: [String], markdown: Substring) -> String {
guard arguments.count == 1 else {
results.invalid(command: .tagLink, markdown)
return ""
}
let tagId = arguments[0]
guard let tag = content.tag(tagId) else {
results.missing(tag: tagId, markdown: markdown)
return ""
}
let localized = tag.localized(in: language)
let url = tag.absoluteUrl(for: language)
let title = localized.name
let description = localized.description ?? ""
let image = localized.linkPreviewImage.map { image in
let size = content.settings.pages.pageLinkImageSize
results.files.insert(image)
results.imagesToGenerate.insert(.init(size: size, image: image))
return RelatedPageLink.Image(
url: image.absoluteUrl,
description: image.getDescription(for: language),
size: size)
}
return RelatedPageLink(
title: title,
description: description,
url: url,
image: image)
.content
}
/**
Format: `![model](<file>)`
*/

View File

@ -5,10 +5,6 @@ import Foundation
*/
enum ShorthandMarkdownKey: String {
/// A standard url
/// Format: `![url](<url>;<text>)`
case url
/// An image
/// Format: `![image](<imageId>;<caption?>]`
case image
@ -37,6 +33,10 @@ enum ShorthandMarkdownKey: String {
/// Format: `![page](<pageId>)`
case pageLink = "page"
/// A pretty link to a tag list on the site.
/// Format: `![tag](<tagId>)`
case tagLink = "tag"
/// Additional HTML code include verbatim into the page.
/// Format: `![html](<fileId>)`
case includedHtml = "html"