Skip to content

Commit 52d1338

Browse files
committed
WIP: Data file download
1 parent bef3b66 commit 52d1338

File tree

5 files changed

+149
-3
lines changed

5 files changed

+149
-3
lines changed

.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+
3+
const download_base = 'datafiles'
4+
const github_base = 'https://github.com/dovecot/documentation'
5+
const lwd = path.dirname(__filename);
6+
7+
export const publicDataDir = path.resolve(lwd, `../public/${download_base}`)
8+
9+
export const dataFileList = [
10+
createEntry(
11+
'doveadm.js',
12+
async () => {
13+
const { loadDoveadm } = await import(path.resolve(lwd, './doveadm.js'))
14+
return await loadDoveadm()
15+
}
16+
),
17+
createEntry(
18+
'event_categories.js',
19+
async () => {
20+
const { loadEventCategories } = await import(path.resolve(lwd, './event_categories.js'))
21+
return await loadEventCategories()
22+
}
23+
),
24+
createEntry(
25+
'event_reasons.js',
26+
async () => {
27+
const { loadEventReasons } = await import(path.resolve(lwd, './event_reasons.js'))
28+
return await loadEventReasons()
29+
}
30+
),
31+
createEntry(
32+
'events.js',
33+
async () => {
34+
const { loadEvents } = await import(path.resolve(lwd, './events.js'))
35+
return await loadEvents()
36+
}
37+
),
38+
createEntry(
39+
'lua.js',
40+
async () => {
41+
const { loadLua } = await import(path.resolve(lwd, './lua.js'))
42+
return await loadLua()
43+
}
44+
),
45+
createEntry(
46+
'settings.js',
47+
async () => {
48+
const { loadSettings } = await import(path.resolve(lwd, './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
}

0 commit comments

Comments
 (0)