|
1 | 1 | import deflistPlugin from 'markdown-it-deflist'
|
2 | 2 | import { createMarkdownRenderer } from 'vitepress'
|
3 |
| -import { loadData, loadDovecotLinks } from './utility.js' |
| 3 | +import { loadData, loadDovecotLinks, resolveURL } from './utility.js' |
4 | 4 |
|
5 | 5 | export async function dovecotMdExtend(md) {
|
6 | 6 | md.use(deflistPlugin)
|
7 | 7 | md.use(dovecot_markdown, {
|
8 |
| - base: globalThis.VITEPRESS_CONFIG.site.base, |
9 | 8 | dovecotlinks: await loadDovecotLinks(),
|
10 | 9 | updates: (await loadData('updates')).updates
|
11 | 10 | })
|
@@ -90,11 +89,6 @@ function dovecot_markdown(md, opts) {
|
90 | 89 | return true
|
91 | 90 | }
|
92 | 91 |
|
93 |
| - function add_base(url) { |
94 |
| - return (opts.base.endsWith('/') ? opts.base.slice(0, -1) : opts.base) |
95 |
| - + '/' + url |
96 |
| - } |
97 |
| - |
98 | 92 | function dovecot_open(tokens, index, mdOpts, env) {
|
99 | 93 | const token = tokens[index]
|
100 | 94 | const mode = token.attrGet('mode')
|
@@ -133,43 +127,36 @@ function dovecot_markdown(md, opts) {
|
133 | 127 | }
|
134 | 128 |
|
135 | 129 | return '<code><a href="' +
|
136 |
| - add_base('core/summaries/' + page + '.html#' + env.inner) + |
| 130 | + resolveURL('core/summaries/' + page + '.html#' + env.inner) + |
137 | 131 | '">'
|
138 | 132 |
|
139 | 133 | case 'link':
|
140 | 134 | let url = '#'
|
141 | 135 | env.inner = false
|
142 | 136 |
|
143 |
| - if (opts.dovecotlinks[parts[1]]) { |
144 |
| - const d = opts.dovecotlinks[parts[1]] |
145 |
| - env.inner = parts[2] ? parts[2] : (d.text ? d.text : false) |
146 |
| - if (d.url) { |
147 |
| - if (d.url.startsWith('http')) { |
148 |
| - url = d.url |
149 |
| - } else { |
150 |
| - url = add_base(d.url) |
151 |
| - } |
152 |
| - } |
153 |
| - } else { |
| 137 | + if (!opts.dovecotlinks[parts[1]]) { |
154 | 138 | throw new Error('Dovecot link missing: ' + parts[1])
|
155 | 139 | }
|
156 | 140 |
|
157 |
| - return '<a href="' + url + '">' |
| 141 | + const d = opts.dovecotlinks[parts[1]] |
| 142 | + env.inner = parts[2] ? parts[2] : (d.text ? d.text : false) |
| 143 | + |
| 144 | + return '<a href="' + d.url + '">' |
158 | 145 |
|
159 | 146 | case 'man':
|
160 | 147 | env.inner = parts[1]
|
161 | 148 | hash = parts[2] ? parts[2] : false;
|
162 | 149 | env.args = parts[3] ? parts[3] : 1;
|
163 | 150 |
|
164 | 151 | return '<code><a href="' +
|
165 |
| - add_base('core/man/' + env.inner + '.' + env.args) + |
| 152 | + resolveURL('core/man/' + env.inner + '.' + env.args) + |
166 | 153 | '.html' + (hash ? '#' + hash : '') + '">'
|
167 | 154 |
|
168 | 155 | case 'plugin':
|
169 | 156 | env.inner = parts[1]
|
170 | 157 |
|
171 | 158 | return '<a href="' +
|
172 |
| - add_base('core/plugins/' + env.inner.replaceAll('-', '_') + |
| 159 | + resolveURL('core/plugins/' + env.inner.replaceAll('-', '_') + |
173 | 160 | '.html' + (parts[2] ? '#' + parts[2] : '')) + '">'
|
174 | 161 |
|
175 | 162 | case 'removed':
|
@@ -217,7 +204,7 @@ function dovecot_markdown(md, opts) {
|
217 | 204 | }
|
218 | 205 |
|
219 | 206 | return '<code><a href="' +
|
220 |
| - add_base('core/settings/variables.html' + hash) + '">' |
| 207 | + resolveURL('core/settings/variables.html' + hash) + '">' |
221 | 208 |
|
222 | 209 | default:
|
223 | 210 | throw new Error('Unknown dovecot markdown command: ' + mode)
|
|
0 commit comments