@samitouri / QOSami-HFS / commits / c8971b78

admin/home: better displaying of changelogs

Massimo Melina committed Aug 3, 2023 at 18:55 UTC c8971b78267c9371a9d048fb3d1263ad50021ce5
2 files changed +9 -5
admin/src/HomePage.ts
+6 -2
@@ -79,7 +79,7 @@ export default function HomePage() {
79 ),
80 plugins.find(x => x.badApi) && entry('warning', "Some plugins may be incompatible"),
81 !account?.adminActualAccess && entry('', md("On _localhost_ you don't need to login"),
82 - SOLUTION_SEP, h(InLink, { to:'accounts' }, md("to access from another computer create an account with /admin/ permission")) ),
82 + SOLUTION_SEP, "to access from another computer ", h(InLink, { to:'accounts' }, md("create an account with *admin* permission")) ),
83 proxyWarning(cfg, status) && entry('warning', proxyWarning(cfg, status),
84 SOLUTION_SEP, cfgLink("set the number of proxies"),
85 SOLUTION_SEP, "unless you are sure and you can ", h(Button, {
@@ -122,11 +122,15 @@ export default function HomePage() {
122 ...!x.isNewer && { color: 'warning', variant: 'outlined' },
123 onClick: () => update(x.tag_name)
124 }, prefix("Install ", x.name, x.isNewer ? '' : " (older)")),
125 - h(Box, { mt: 1 }, md(x.body, { onText, linkTarget: '_blank' }))
125 + h(Box, { mt: 1 }, renderChangelog(x.body))
126 )),
127 )),
128 ))
129 )
130 +}
131 +
132 +function renderChangelog(s: string) {
133 + return md(s, { onText, linkTarget: '_blank' })
134
135 function onText(s: string) {
136 return replaceStringToReact(s, /(?<=^|\W)#(\d+)\b/g, m => // link issues
admin/src/md.ts
+3 -3
@@ -5,8 +5,8 @@ import { Link } from '@mui/material'
5
6 const TAGS = {
7 '`': 'code',
8 - '*': 'b',
9 - '/': 'i',
8 + '*': 'i',
9 + '**': 'b',
10 '_': 'u',
11 }
12 // markdown inspired syntax to transform text into react elements: * for bold, / for italic, _ for underline, ` for code
@@ -14,7 +14,7 @@ type OnText = (s: string) => ReactNode
14 export default function md(text: string | TemplateStringsArray, { linkTarget='', onText=(x=>x) as OnText }={}) {
15 if (typeof text !== 'string')
16 text = text[0]
17 - return replaceStringToReact(text, /([`*/_])(.+)\1|(\n)|\[(.+)\]\((.+)\)/g, m =>
17 + return replaceStringToReact(text, /(`|_|\*\*?)(.+)\1|(\n)|\[(.+)\]\((.+)\)/g, m =>
18 m[4] ? h(Link, { href: m[5], target: linkTarget }, onText(m[4]))
19 : m[3] ? h('br')
20 : h((TAGS as any)[ m[1] ], {}, onText(m[2])),