Skip to content

Commit c23e6a8

Browse files
committed
cleanup
1 parent 879b299 commit c23e6a8

File tree

2 files changed

+47
-65
lines changed

2 files changed

+47
-65
lines changed

packages/apps/docs/src/scripts/build.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const initFunc = async (fnc, description) => {
7474
};
7575

7676
(async function () {
77+
//starting with a cleanslate, removing the tempdir
7778
deleteTempDir();
7879
await initFunc(importAllReadmes, 'Import docs from monorepo');
7980
await initFunc(createDocsTree, 'Create docs tree');
@@ -83,8 +84,9 @@ const initFunc = async (fnc, description) => {
8384
await initFunc(checkAuthors, 'Check author data for blog');
8485
await initFunc(createSitemap, 'Create the sitemap');
8586
await initFunc(copyFavIcons, 'Copy favicons');
86-
deleteTempDir();
8787
await initFunc(runPrettier, 'Prettier');
88+
//cleanup, removing the tempdir
89+
deleteTempDir();
8890

8991
if (globalError) {
9092
process.exitCode = 1;

packages/apps/docs/src/scripts/importReadme/createDoc.mjs

+44-64
Original file line numberDiff line numberDiff line change
@@ -202,82 +202,62 @@ const relinkReferences = (md, pages, root) => {
202202
relinkImageReferences(imageReferences, definitions, pages, root);
203203
};
204204

205-
export const importDocs = async (filename, item) => {
206-
const doc = fs.readFileSync(`${filename}`, 'utf-8');
207-
208-
const md = remark.parse(doc);
205+
const createPage = async (page, filename, item, hasMulitplePages, idx) => {
206+
if (hasMulitplePages) {
207+
createDir(`${DOCSROOT}/${item.destination}`);
208+
}
209209

210210
const lastModifiedDate = await getLastModifiedDate(
211211
`.${removeRepoDomain(item.repo)}${item.file}`,
212212
);
213213

214-
if (item.options.singlePage) {
215-
relinkReferences(md, [md], `/${item.destination}/`);
214+
const title = getTitle(page);
215+
const slug =
216+
idx === 0 || item.options.RootOrder === 0 ? 'index' : createSlug(title);
217+
const menuTitle =
218+
idx === 0 || item.options.RootOrder === 0 ? item.title : title;
219+
const order = idx === 0 ? item.options.RootOrder : idx ? idx : 0;
220+
221+
// check that there is just 1 h1.
222+
// if more, keep only 1 and replace the next with an h2
223+
const pageContent = cleanUp(
224+
page,
225+
`/${item.destination}/${order === 0 ? '' : slug}`,
226+
);
216227

217-
const title = getTitle(md);
218-
219-
const menuTitle = item.title;
220-
const order = item.options.RootOrder;
221-
const slug = createSlug(title);
222-
223-
// check that there is just 1 h1.
224-
// if more, keep only 1 and replace the next with an h2
225-
226-
const pageContent = cleanUp(
227-
md,
228-
`/${item.destination}/${order === 0 ? '' : slug}`,
229-
);
230-
231-
const doc = toMarkdown(pageContent);
232-
233-
fs.writeFileSync(
234-
`${DOCSROOT}/${item.destination}/${order === 0 ? 'index' : slug}.md`,
235-
createFrontMatter(
236-
title,
237-
menuTitle,
238-
order,
239-
createEditOverwrite(item),
240-
item.options.tags,
241-
lastModifiedDate,
242-
) + doc,
243-
{
244-
flag: 'w',
245-
},
246-
);
228+
const doc = toMarkdown(pageContent);
229+
230+
fs.writeFileSync(
231+
`${DOCSROOT}/${item.destination}/${order === 0 ? 'index' : slug}.md`,
232+
createFrontMatter(
233+
title,
234+
menuTitle,
235+
order,
236+
createEditOverwrite(item),
237+
item.options.tags,
238+
lastModifiedDate,
239+
) + doc,
240+
{
241+
flag: 'w',
242+
},
243+
);
244+
};
247245

246+
export const importDocs = async (filename, item) => {
247+
const doc = fs.readFileSync(`${filename}`, 'utf-8');
248+
249+
const md = remark.parse(doc);
250+
251+
if (item.options.singlePage) {
252+
relinkReferences(md, [md], `/${item.destination}/`);
253+
await createPage(md, filename, item);
248254
return;
249255
}
250256

251257
const pages = divideIntoPages(md);
252258
relinkReferences(md, pages, `/${item.destination}/`);
253259

254-
pages.forEach((page, idx) => {
255-
const title = getTitle(page);
256-
const slug = idx === 0 ? 'index' : createSlug(title);
257-
const menuTitle = idx === 0 ? item.title : title;
258-
const order = idx === 0 ? item.options.RootOrder : idx;
259-
260-
// check that there is just 1 h1.
261-
// if more, keep only 1 and replace the next with an h2
262-
const pageContent = cleanUp(page, `/${item.destination}/${slug}`);
263-
264-
const doc = toMarkdown(pageContent);
265-
266-
createDir(`${DOCSROOT}/${item.destination}`);
267-
268-
fs.writeFileSync(
269-
`${DOCSROOT}/${item.destination}/${slug}.md`,
270-
createFrontMatter(
271-
title,
272-
menuTitle,
273-
order,
274-
createEditOverwrite(item),
275-
item.options.tags,
276-
lastModifiedDate,
277-
) + doc,
278-
{
279-
flag: 'w',
280-
},
281-
);
260+
pages.forEach(async (page, idx) => {
261+
await createPage(page, filename, item, true, idx);
282262
});
283263
};

0 commit comments

Comments
 (0)