Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: make docs work on windows #821

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ module.exports = {
'academy$',
...collectSlugs(`${__dirname}/sources/academy/webscraping`),
...collectSlugs(`${__dirname}/sources/academy/platform`),
].join('|'),
].join('$|'),
},
{
label: 'Tutorials',
to: `/academy/tutorials`,
activeBaseRegex: collectSlugs(`${__dirname}/sources/academy/tutorials`).join('|'),
activeBaseRegex: collectSlugs(`${__dirname}/sources/academy/tutorials`).join('$|'),
},
{
label: 'Glossary',
to: `/academy/glossary`,
activeBaseRegex: collectSlugs(`${__dirname}/sources/academy/glossary`).join('|'),
activeBaseRegex: collectSlugs(`${__dirname}/sources/academy/glossary`).join('$|'),
vladfrangu marked this conversation as resolved.
Show resolved Hide resolved
},
],
},
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
30 changes: 27 additions & 3 deletions tools/utils/collectSlugs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
const { execSync } = require('child_process');
const { opendirSync, readFileSync } = require('fs');

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(`${pathname}/${direntry.name}`, { encoding: 'utf-8' });
vladfrangu marked this conversation as resolved.
Show resolved Hide resolved

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

if (direntry.isDirectory()) {
const dirPath = `${pathname}/${direntry.name}`;
const dirRes = collectSlugs(dirPath);
res.push(...dirRes);
}
}

dir.closeSync();

return res;
}

module.exports = {
Expand Down