Skip to content

Commit

Permalink
docs: make docs work on windows (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu authored Jan 11, 2024
1 parent 7e59861 commit 1541f74
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 12 deletions.
13 changes: 7 additions & 6 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { join } = require('path');
const { config } = require('./apify-docs-theme');
const { externalLinkProcessor } = require('./tools/utils/externalLink');
const { collectSlugs } = require('./tools/utils/collectSlugs');
Expand Down Expand Up @@ -30,21 +31,21 @@ module.exports = {
{
label: 'Courses',
to: `/academy`,
activeBaseRegex: [
activeBaseRegex: `${[
'academy$',
...collectSlugs(`${__dirname}/sources/academy/webscraping`),
...collectSlugs(`${__dirname}/sources/academy/platform`),
].join('|'),
...collectSlugs(join(__dirname, 'sources', 'academy', 'webscraping')),
...collectSlugs(join(__dirname, 'sources', 'academy', 'platform')),
].join('$|')}$`,
},
{
label: 'Tutorials',
to: `/academy/tutorials`,
activeBaseRegex: collectSlugs(`${__dirname}/sources/academy/tutorials`).join('|'),
activeBaseRegex: `${collectSlugs(join(__dirname, 'sources', 'academy', 'tutorials')).join('$|')}$`,
},
{
label: 'Glossary',
to: `/academy/glossary`,
activeBaseRegex: collectSlugs(`${__dirname}/sources/academy/glossary`).join('|'),
activeBaseRegex: `${collectSlugs(join(__dirname, 'sources', 'academy', 'glossary')).join('$|')}$`,
},
],
},
Expand Down
203 changes: 203 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
},
"homepage": "https://github.com/apify/apify-docs#readme",
"scripts": {
"start": "rimraf .docusaurus && LOCALHOST=1 docusaurus start",
"start:dev": "rimraf .docusaurus && DEV=1 docusaurus start",
"start": "rimraf .docusaurus && cross-env LOCALHOST=1 CRAWLEE_DOCS_FAST=1 docusaurus start",
"start:dev": "rimraf .docusaurus && cross-env DEV=1 CRAWLEE_DOCS_FAST=1 docusaurus start",
"build": "rimraf .docusaurus && docusaurus build",
"publish-gh-pages": "docusaurus-publish",
"write-translations": "docusaurus write-translations",
Expand All @@ -26,7 +26,7 @@
"swizzle": "docusaurus swizzle",
"deploy": "rimraf .docusaurus && docusaurus deploy",
"docusaurus": "docusaurus",
"postinstall": "npx patch-package",
"postinstall": "patch-package",
"lint": "npm run lint:md && npm run lint:code",
"lint:fix": "npm run lint:md:fix && npm run lint:code:fix",
"lint:md": "markdownlint '**/*.md'",
Expand All @@ -40,6 +40,7 @@
"@types/react": "^18.2.8",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"cross-env": "^7.0.3",
"eslint": "^8.46.0",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-markdown": "^3.0.1",
Expand All @@ -49,6 +50,7 @@
"globby": "^14.0.0",
"markdownlint": "^0.32.0",
"markdownlint-cli": "^0.38.0",
"patch-package": "^8.0.0",
"path-browserify": "^1.0.1",
"rimraf": "^5.0.1",
"typescript": "^5.1.3"
Expand Down
31 changes: 28 additions & 3 deletions tools/utils/collectSlugs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
const { execSync } = require('child_process');
const { opendirSync, readFileSync } = require('fs');
const { join } = require('path');

function collectSlugs(pathname) {
const a = execSync(`find ${pathname} -type f -name "*.md" -exec grep slug: {} \\;`, { encoding: 'utf-8' });
return a.split('\n').filter((x) => x.startsWith('slug: ')).map((x) => x.replace('slug: ', ''));
const dir = opendirSync(pathname);
const res = [];

let direntry;

// eslint-disable-next-line no-cond-assign
while ((direntry = dir.readSync()) !== null) {
if (direntry.isFile() && direntry.name.endsWith('.md')) {
const mdContent = readFileSync(join(pathname, direntry.name), { encoding: 'utf-8' });

const slugMatch = mdContent.match(/^slug: (.*)$/m);
if (slugMatch) {
res.push(slugMatch[1]);
}
}

if (direntry.isDirectory()) {
const dirPath = join(pathname, direntry.name);
const dirRes = collectSlugs(dirPath);
res.push(...dirRes);
}
}

dir.closeSync();

return res;
}

module.exports = {
Expand Down

0 comments on commit 1541f74

Please sign in to comment.