Skip to content

Commit fe7be47

Browse files
committed
fix the lastmodified dates
1 parent b30ce75 commit fe7be47

File tree

9 files changed

+102
-71
lines changed

9 files changed

+102
-71
lines changed

packages/apps/docs/src/pages/pact/beginner/loans.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ inside of the repository you cloned.
539539
For help getting started and deploying in each of these environments, try the
540540
following tutorials.
541541

542-
- [Pact Online Editor](//pact/beginner/web-editor)
542+
- [Pact Online Editor](/pact/beginner/web-editor)
543543
- [Pact Development on Atom SDK Tutorial](/pact/beginner/atom-sdk)
544544

545545
## Review

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

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createSitemap } from './createSitemap.mjs';
88
import { createSpecs } from './createSpec.mjs';
99
import { detectBrokenLinks } from './detectBrokenLinks.mjs';
1010
import { createDocsTree } from './getdocstree.mjs';
11+
import { deleteTempDir } from './importReadme/importRepo.mjs';
1112
import { importAllReadmes } from './importReadme/index.mjs';
1213
import { Spinner } from './spinner.mjs';
1314

@@ -73,6 +74,7 @@ const initFunc = async (fnc, description) => {
7374
};
7475

7576
(async function () {
77+
deleteTempDir();
7678
await initFunc(importAllReadmes, 'Import docs from monorepo');
7779
await initFunc(createDocsTree, 'Create docs tree');
7880
await initFunc(createSpecs, 'Create specs files');
@@ -81,6 +83,7 @@ const initFunc = async (fnc, description) => {
8183
await initFunc(checkAuthors, 'Check author data for blog');
8284
await initFunc(createSitemap, 'Create the sitemap');
8385
await initFunc(copyFavIcons, 'Copy favicons');
86+
deleteTempDir();
8487
await initFunc(runPrettier, 'Prettier');
8588

8689
if (globalError) {

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as fs from 'fs';
33
import yaml from 'js-yaml';
44
import { promisify } from 'util';
55
import { TEMPDIR } from './importReadme/createDoc.mjs';
6-
import { deleteTempDir } from './importReadme/importRepo.mjs';
76

87
const errors = [];
98
const success = [];
@@ -15,7 +14,11 @@ const promiseExec = promisify(exec);
1514
* @param {ImportItem} importItem
1615
*/
1716
const clone = async () => {
18-
await promiseExec(`git clone https://github.com${REPO} ${TEMPDIR}${REPO}`);
17+
try {
18+
await promiseExec(`git clone https://github.com${REPO} ${TEMPDIR}${REPO}`);
19+
} catch (e) {
20+
Promise.resolve();
21+
}
1922
};
2023

2124
const returnJSON = (filename) => {
@@ -30,7 +33,6 @@ const returnJSON = (filename) => {
3033

3134
success.push(`Successfully created spec for ${filename}!`);
3235
} catch (error) {
33-
deleteTempDir();
3436
errors.push(`creating spec for ${filename} failed: ${error}`);
3537
}
3638
};
@@ -40,6 +42,5 @@ export const createSpecs = async () => {
4042
returnJSON('chainweb.openapi');
4143
returnJSON('pact.openapi');
4244

43-
deleteTempDir();
4445
return { success, errors };
4546
};

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,12 @@ const isMarkDownFile = (name) => {
2424
};
2525

2626
export const getLastModifiedDate = async (root) => {
27-
try {
28-
await promiseExec(
29-
`git clone https://github.com/kadena-community/kadena.js.git ${TEMPDIR}/kadena-community/kadena.js`,
30-
);
31-
} catch (e) {}
32-
3327
const rootArray = root.split('/');
3428
const filename = rootArray.pop();
3529
const newRoot = rootArray.join('/');
3630

3731
const { stdout } = await promiseExec(
38-
`cd ${newRoot} && git log -1 --pretty="format:%ci" ${filename}`,
32+
`cd ${TEMPDIR} && cd ${newRoot} && git log -1 --pretty="format:%ci" ${filename}`,
3933
);
4034

4135
const date = new Date(stdout);
@@ -67,7 +61,14 @@ const convertFile = async (file) => {
6761
if (!data) return;
6862

6963
const readTime = getReadTime(doc);
70-
const lastModifiedDate = await getLastModifiedDate(file);
64+
const lastModifiedDate = data.lastModifiedDate
65+
? data.lastModifiedDate
66+
: await getLastModifiedDate(
67+
`./kadena-community/kadena.js/packages/apps/docs/${file.substr(
68+
2,
69+
file.length - 1,
70+
)}`,
71+
);
7172

7273
return {
7374
lastModifiedDate,

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

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import { exec } from 'child_process';
12
import 'dotenv/config';
23
import * as fs from 'fs';
34
import { toMarkdown } from 'mdast-util-to-markdown';
45
import { toString } from 'mdast-util-to-string';
56
import { remark } from 'remark';
7+
import { promisify } from 'util';
68
import { getLastModifiedDate } from './../getdocstree.mjs';
79
import { getTypes } from './../utils.mjs';
10+
import { removeRepoDomain } from './index.mjs';
811

9-
const DOCSROOT = './src/pages/';
10-
export const REPOPREFIX = 'https://github.com/';
12+
const promiseExec = promisify(exec);
13+
const DOCSROOT = './src/pages';
1114
export const TEMPDIR = './.tempimport';
1215

1316
const createFrontMatter = (
@@ -32,12 +35,9 @@ lastModifiedDate: ${lastModifiedDate}
3235
`;
3336
};
3437

35-
const createEditOverwrite = (filename, options, repo) => {
36-
if (options.hideEditLink) return '';
37-
if (repo) {
38-
return `${REPOPREFIX}${repo}/edit/main/${filename}`;
39-
}
40-
return `${process.env.NEXT_PUBLIC_GIT_EDIT_ROOT}/packages/${filename}`;
38+
const createEditOverwrite = (item) => {
39+
if (item.options.hideEditLink) return '';
40+
return `${item.repo}/edit/main${item.file}`;
4141
};
4242

4343
export const createSlug = (str) => {
@@ -206,11 +206,13 @@ const relinkReferences = (md, pages, root) => {
206206
};
207207

208208
export const importDocs = async (filename, item) => {
209-
const doc = fs.readFileSync(filename, 'utf-8');
209+
const doc = fs.readFileSync(`${filename}`, 'utf-8');
210210

211211
const md = remark.parse(doc);
212212

213-
const lastModifiedDate = await getLastModifiedDate(filename);
213+
const lastModifiedDate = await getLastModifiedDate(
214+
`.${removeRepoDomain(item.repo)}${item.file}`,
215+
);
214216

215217
if (item.options.singlePage) {
216218
relinkReferences(md, [md], `/${item.destination}/`);
@@ -232,12 +234,12 @@ export const importDocs = async (filename, item) => {
232234
const doc = toMarkdown(pageContent);
233235

234236
fs.writeFileSync(
235-
`${DOCSROOT}${item.destination}/${order === 0 ? 'index' : slug}.md`,
237+
`${DOCSROOT}/${item.destination}/${order === 0 ? 'index' : slug}.md`,
236238
createFrontMatter(
237239
title,
238240
menuTitle,
239241
order,
240-
createEditOverwrite(item.file, item.options, item.repo),
242+
createEditOverwrite(item),
241243
item.options.tags,
242244
lastModifiedDate,
243245
) + doc,
@@ -264,15 +266,15 @@ export const importDocs = async (filename, item) => {
264266

265267
const doc = toMarkdown(pageContent);
266268

267-
createDir(`${DOCSROOT}${item.destination}`);
269+
createDir(`${DOCSROOT}/${item.destination}`);
268270

269271
fs.writeFileSync(
270-
`${DOCSROOT}${item.destination}/${slug}.md`,
272+
`${DOCSROOT}/${item.destination}/${slug}.md`,
271273
createFrontMatter(
272274
title,
273275
menuTitle,
274276
order,
275-
createEditOverwrite(item.file, item.options),
277+
createEditOverwrite(item),
276278
item.options.tags,
277279
lastModifiedDate,
278280
) + doc,

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { exec } from 'child_process';
22
import * as fs from 'fs';
33
import { promisify } from 'util';
4-
import { REPOPREFIX, TEMPDIR, importDocs } from './createDoc.mjs';
4+
import { TEMPDIR, importDocs } from './createDoc.mjs';
5+
import { removeRepoDomain } from './index.mjs';
56

67
const promiseExec = promisify(exec);
78

@@ -16,14 +17,18 @@ export const deleteTempDir = () => {
1617
* @param {ImportItem} importItem
1718
*/
1819
const clone = async ({ repo }) => {
19-
deleteTempDir();
20-
21-
await promiseExec(`git clone ${REPOPREFIX}${repo} ${TEMPDIR}/${repo}`);
20+
try {
21+
await promiseExec(`git clone ${repo} ${TEMPDIR}/${removeRepoDomain(repo)}`);
22+
} catch (e) {
23+
Promise.resolve();
24+
}
2225
};
2326

2427
export const importRepo = async (item) => {
2528
await clone(item);
26-
await importDocs(`${TEMPDIR}/${item.repo}/${item.file}`, item);
2729

28-
deleteTempDir();
30+
await importDocs(
31+
`${TEMPDIR}${removeRepoDomain(item.repo)}${item.file}`,
32+
item,
33+
);
2934
};

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

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
import { importReadMes } from './../utils.mjs';
2-
import { importDocs } from './createDoc.mjs';
32
import { importRepo } from './importRepo.mjs';
43

54
const errors = [];
65
const success = [];
76

7+
export const removeRepoDomain = (repo) =>
8+
repo.replace(/https:\/\/github.com/, '');
9+
810
export const importAllReadmes = async () => {
911
let monorepoCount = 0;
1012
let outsideCount = 0;
11-
const promises = importReadMes.map((item) => {
12-
if (item.repo) {
13-
outsideCount++;
14-
return importRepo(item);
15-
} else {
16-
monorepoCount++;
17-
return importDocs(`./../../${item.file}`, item);
18-
}
19-
});
2013

21-
await Promise.all(promises);
14+
for (const item of importReadMes) {
15+
outsideCount++;
16+
await importRepo(item);
17+
}
2218

2319
success.push(
2420
`Docs imported from monorepo(${monorepoCount}) and outside repos(${outsideCount})`,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const getCurrentPostFromJson = (root) => {
2323
const data = getFlatData();
2424

2525
return data.find((item) => {
26-
return item && item.root === root;
26+
return item && (item.root === root || `${item.root}/` === root);
2727
});
2828
};
2929

0 commit comments

Comments
 (0)