Skip to content

Commit

Permalink
generate_man: Find includes in multiple places
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse authored and sirainen committed Aug 26, 2024
1 parent f22b926 commit bb75e56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export async function manFiles() {
[ 'docs/core/man/*.[[:digit:]].md' ]
}

export async function manIncludes() {
const lconf = await loadLocalConf()
return lconf?.man_includes ??
[ 'docs/core/man/include/*.inc' ]
}

export async function pluginFiles() {
/* Check for config override file. */
const lconf = await loadLocalConf()
Expand Down
18 changes: 12 additions & 6 deletions util/generate_man.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import matter from 'gray-matter'
import pdc from 'pdc'
import path from 'path'
import { VFile } from 'vfile'
import { manFiles } from '../lib/utility.js'
import { manFiles, manIncludes } from '../lib/utility.js'
import remarkDeflist from 'remark-definition-list'
import remarkMan from 'remark-man'
import remarkParse from 'remark-parse'
Expand Down Expand Up @@ -42,12 +42,18 @@ program
.parse()
const debug = program.opts().debug

const doInclude = (content, f) => {
return content.replace(includesRE, (m, m1) => {
const doInclude = async (content, f) => {
const files = (await manIncludes()).flatMap((x) => fg.sync(x))
const result = await content.replace(includesRE, async (m, m1) => {
if (!m1.length) return m
const inc_f = path.join(path.dirname(f), m1)
return doInclude(fs.readFileSync(inc_f, 'utf8'), inc_f)
for (const fn of files)
if (path.basename(fn) == path.basename(m1)) {
const result = await doInclude(fs.readFileSync(fn, 'utf8'), f)
return result
}
throw new Error("Missing include " + fn)
})
return result
}

const processDovecotMd = () => {
Expand Down Expand Up @@ -136,7 +142,7 @@ const main = async (component, outPath) => {
const page = matter(str)
const vf = new VFile({
path: f,
value: doInclude(page.content, f)
value: await doInclude(page.content, f)
})
if (page.data.dovecotComponent != component)
continue
Expand Down

0 comments on commit bb75e56

Please sign in to comment.