From 0bc7161dbc9af8fb9b96343227f03c3e0d35f76f Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 22 Jan 2024 14:30:51 +0800 Subject: [PATCH] WIP: Settings schema spike --- .../components/custom-header-links.js | 21 +++---- settings.yml | 61 +++++++++++++++++++ 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/javascripts/discourse/components/custom-header-links.js b/javascripts/discourse/components/custom-header-links.js index 934559f..8d5f26b 100644 --- a/javascripts/discourse/components/custom-header-links.js +++ b/javascripts/discourse/components/custom-header-links.js @@ -3,20 +3,18 @@ import { dasherize } from "@ember/string"; export default class CustomHeaderLinks extends Component { get shouldShow() { - return settings.Custom_header_links?.length > 0; + return settings.links?.length > 0; } get links() { - return settings.Custom_header_links.split("|").reduce((result, item) => { - let [ - linkText, - linkTitle, - linkHref, - device, - target = "", - keepOnScroll, - locale, - ] = item.split(",").map((s) => s.trim()); + return settings.links.reduce((result, link) => { + const linkText = link.text; + const linkTitle = link.title; + const linkHref = link.url; + const target = link.target; + const keepOnScroll = link.hide_on_scroll; + const locale = link.locale; + const device = link.view; if (!linkText || (locale && document.documentElement.lang !== locale)) { return result; @@ -33,7 +31,6 @@ export default class CustomHeaderLinks extends Component { result.push({ device: `headerLink--${device}`, keepOnScroll: `headerLink--${keepOnScroll}`, - locale: `headerLink--${locale}`, linkClass, anchorAttributes, linkText, diff --git a/settings.yml b/settings.yml index 063d5c7..6c120dc 100644 --- a/settings.yml +++ b/settings.yml @@ -5,6 +5,67 @@ Custom_header_links: description: en: "Comma delimited in this order: link text, link title, URL, view, target, hide on scroll
Link text: The text for the link
Link title: the text that shows when the link is hovered
URL: The path for the link (can be relative)
View: vdm = desktop and mobile, vdo = desktop only, vmo = mobile only
Target: blank = opens in a new tab, self = opens in the same tab
Hide on scroll: remove = hides the link when the title is expanded on topic pages keep = keeps the link visible even when the title is visible on topic pages
Language: blank = no locale assoaciated to the link, else insert a locale code (en, fr, de, ...)" +links: + type: objects + default: + - text: "External link" + title: "This link will open in a new tab" + url: "https://meta.discourse.org" + view: "vdo" + target: "blank" + hide_on_scroll: "remove" + - text: "Most Liked" + title: "Posts with the most amount of likes" + url: "/latest/?order=op_likes" + view: "vdo" + target: "self" + hide_on_scroll: "keep" + - text: "Privacy" + title: "Our Privacy Policy" + url: "/privacy" + view: "vdm" + target: "self" + hide_on_scroll: "keep" + schema: + name: link + fields: + - name: text + type: string + required: true + validations: + min_length: 5 + max_length: 100 + - name: title + type: string + required: true + validations: + min_length: 5 + max_length: 100 + - name: url + type: string + required: true + validations: + min_length: 0 + max_length: 2048 + url: true + - name: view + type: enum + choices: + - vdm + - vdo + - vmo + - name: target + type: enum + choices: + - blank + - self + - name: hide_on_scroll + type: enum + choices: + - remove + - keep + default: keep + links_position: default: right type: enum