Skip to content

Commit fe13c5d

Browse files
committed
datafiles: Add ability to download raw "data files" used to build documentation
Providing static versions of the fully parsed/transformed data files used to build the documentation may be useful, since it allows things like, e.g., parsing the settings or doveadm config files for use in automated coding and tasks.
1 parent bef3b66 commit fe13c5d

File tree

7 files changed

+154
-6
lines changed

7 files changed

+154
-6
lines changed

.github/actions/spelling/expect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ cydir
119119
cyrusimap
120120
datacenter
121121
DATAERR
122+
datafiles
122123
datalake
123124
datastack
124125
datastax
@@ -541,6 +542,7 @@ noout
541542
nopassword
542543
nopipelining
543544
nordirplus
545+
noreferrer
544546
noscheme
545547
noselect
546548
nosep

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ lib/data/*.mjs
1313
.vitepress/local.js
1414
.vitepress/.temp
1515
/man/
16+
public/datafiles/

docs/core/datafiles.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
layout: doc
3+
title: Raw Data Files
4+
---
5+
6+
<script setup>
7+
import { data } from '../../lib/data/datafiles.data.js'
8+
import { withBase } from 'vitepress'
9+
</script>
10+
11+
# Raw Data Files
12+
13+
This page provides download links to the raw data files used to generate the
14+
Dovecot documentation.
15+
16+
The format and content of each data file is available by looking at the data
17+
file source in GitHub (links for each file below).
18+
19+
## Data File List
20+
21+
<table>
22+
<thead>
23+
<tr>
24+
<th>File</th>
25+
<th>Source</th>
26+
</tr>
27+
</thead>
28+
<tbody>
29+
<tr v-for="file in data.files">
30+
<td>
31+
<code>
32+
<a :href="withBase(file.download)" target="_blank" rel="noreferrer">{{ file.name }}</a>
33+
</code>
34+
</td>
35+
<td>
36+
<a :href="file.github" target="_blank" rel="noreferrer">Source</a>
37+
</td>
38+
</tr>
39+
</tbody>
40+
</table>

lib/data/datafiles.data.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { dataFileList } from '../datafiles.js'
2+
3+
const filedata = []
4+
for (const d of dataFileList) {
5+
filedata.push({
6+
download: d.download,
7+
github: d.github,
8+
name: d.name
9+
})
10+
}
11+
12+
export default {
13+
load() {
14+
return { files: filedata }
15+
}
16+
}

lib/datafiles.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import path from 'path'
2+
import { lib_dirname } from './utility.js'
3+
4+
const download_base = 'datafiles'
5+
const github_base = 'https://github.com/dovecot/documentation'
6+
7+
export const publicDataDir = path.resolve(lib_dirname, `../public/${download_base}`)
8+
9+
export const dataFileList = [
10+
createEntry(
11+
'doveadm.js',
12+
async () => {
13+
const { loadDoveadm } = await import(path.resolve(lib_dirname, './doveadm.js'))
14+
return await loadDoveadm()
15+
}
16+
),
17+
createEntry(
18+
'event_categories.js',
19+
async () => {
20+
const { loadEventCategories } = await import(path.resolve(lib_dirname, './event_categories.js'))
21+
return await loadEventCategories()
22+
}
23+
),
24+
createEntry(
25+
'event_reasons.js',
26+
async () => {
27+
const { loadEventReasons } = await import(path.resolve(lib_dirname, './event_reasons.js'))
28+
return await loadEventReasons()
29+
}
30+
),
31+
createEntry(
32+
'events.js',
33+
async () => {
34+
const { loadEvents } = await import(path.resolve(lib_dirname, './events.js'))
35+
return await loadEvents()
36+
}
37+
),
38+
createEntry(
39+
'lua.js',
40+
async () => {
41+
const { loadLua } = await import(path.resolve(lib_dirname, './lua.js'))
42+
return await loadLua()
43+
}
44+
),
45+
createEntry(
46+
'settings.js',
47+
async () => {
48+
const { loadSettings } = await import(path.resolve(lib_dirname, './settings.js'))
49+
return await loadSettings()
50+
}
51+
)
52+
]
53+
54+
function createEntry(id, func) {
55+
const json = `${path.basename(id, '.js')}.json`
56+
57+
return {
58+
data: func,
59+
download: `/${download_base}/${json}`,
60+
github: `${github_base}/blob/main/data/${id}`,
61+
json: path.resolve(publicDataDir, json),
62+
name: json
63+
}
64+
}

lib/dovecot_vitepress_init.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
1+
import { dataFileList, publicDataDir } from './datafiles.js'
12
import { dovecotMdInit } from './markdown.js'
3+
import fs from 'fs'
4+
5+
let has_run = false
26

37
export default function dovecotVitepressInit() {
48
return {
59
name: 'dovecot-vitepress-init',
610
async configResolved(config) {
7-
console.log('\n✅ Config resolved!')
11+
/*** Init Dovecot Markdown. ***/
812

913
/* We need to synchronously initialize markdown,
1014
* since we need to pre-populate various internal
1115
* tables (e.g. links). */
1216
await dovecotMdInit()
13-
console.log('\n✅ Markdown initialized!')
14-
},
17+
console.log('\n✅ Dovecot Markdown initialized.')
18+
19+
/*** Create static downloadable data files. ***/
20+
21+
if (has_run) {
22+
return
23+
}
24+
has_run = true
25+
26+
/* Clean old data files (if they exist) and prepare directory. */
27+
fs.rmSync(publicDataDir, { force: true, recursive: true });
28+
fs.mkdirSync(publicDataDir, { recursive: true });
29+
console.log(`✅ Data files: Created ${publicDataDir}.`)
30+
31+
/* Build the data files. */
32+
for (const d of dataFileList) {
33+
fs.writeFileSync(
34+
d.json,
35+
JSON.stringify(await d.data(), null, 2)
36+
)
37+
console.log(`✅ Data files: Generated ${d.json}.`)
38+
}
39+
}
1540
}
1641
}

lib/utility.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { dirname } from 'path'
77
import { fileURLToPath } from 'url'
88

99
const __filename = fileURLToPath(import.meta.url);
10-
const __dirname = dirname(__filename);
10+
export const lib_dirname = dirname(__filename);
1111

1212
export function normalizeArrayData(data, keys) {
1313
for (const [k, v] of Object.entries(data)) {
@@ -33,9 +33,9 @@ export async function loadData(id) {
3333
?? ('../data/' + id + '.js')
3434

3535
try {
36-
dataOb[id] = await import(__dirname + '/' + path)
36+
dataOb[id] = await import(lib_dirname + '/' + path)
3737
} catch (e) {
38-
throw new Error('Unable to import module (' + __dirname + '/' +
38+
throw new Error('Unable to import module (' + lib_dirname + '/' +
3939
path + '):' + e)
4040
}
4141
}

0 commit comments

Comments
 (0)