Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,6 @@ jobs:
- uses: apify/workflows/pnpm-install@main

- run: pnpm lint:code

- name: Format check
run: pnpm format:check
21 changes: 21 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"printWidth": 120,
Comment thread
fnesveda marked this conversation as resolved.
"ignorePatterns": [
"**/*.md",
"**/*.mdx",
"**/*.json",
"**/*.jsonc",
"**/*.yaml",
"**/*.yml",
"**/*.toml",
"**/node_modules",
"**/dist",
"**/build",
".docusaurus",
"coverage",
"patches",
"sources",
"apify-api",
"examples"
]
}
4 changes: 1 addition & 3 deletions apify-docs-theme/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ const plugins = [
return {
resolveLoader: {
alias: {
'roa-loader': require.resolve(
`${__dirname}/roa-loader/`,
),
'roa-loader': require.resolve(`${__dirname}/roa-loader/`),
},
},
};
Expand Down
14 changes: 8 additions & 6 deletions apify-docs-theme/src/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const incrementHeadingLevels = () => (tree) => {

const removeGitCliffMarkers = () => (tree) => {
visitParents(tree, 'html', (node) => {
const gitCliffMarkerRegex = /generated by git-cliff|git-cliff-unreleased/ig;
const gitCliffMarkerRegex = /generated by git-cliff|git-cliff-unreleased/gi;
const match = gitCliffMarkerRegex.exec(node.value);

if (match) node.value = '';
Expand Down Expand Up @@ -127,11 +127,13 @@ ${changelog}`;
* @returns {string} The markdown content with escaped MDX characters.
*/
function escapeMDXCharacters(changelog) {
return changelog.replaceAll(/<|>/g, (match) => {
return match === '<' ? '&lt;' : '&gt;';
}).replaceAll(/\{|\}/g, (match) => {
return match === '{' ? '&#123;' : '&#125;';
});
return changelog
.replaceAll(/<|>/g, (match) => {
return match === '<' ? '&lt;' : '&gt;';
})
.replaceAll(/\{|\}/g, (match) => {
return match === '{' ? '&#123;' : '&#125;';
});
}

/**
Expand Down
30 changes: 16 additions & 14 deletions apify-docs-theme/src/roa-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ async function getHash(source) {
}

const memory = source.match(/playwright|puppeteer/i) ? 4096 : 1024;
const res = await (await fetch(signingUrl, {
method: 'POST',
body: JSON.stringify({
input: JSON.stringify({ code: source }),
options: {
build: 'latest',
contentType: 'application/json; charset=utf-8',
memory,
timeout: 180,
const res = await (
await fetch(signingUrl, {
method: 'POST',
body: JSON.stringify({
input: JSON.stringify({ code: source }),
options: {
build: 'latest',
contentType: 'application/json; charset=utf-8',
memory,
timeout: 180,
},
}),
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
}),
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
})).json();
})
).json();

if (!res.data || !res.data.encoded) {
console.error(`Signing failed:' ${inspect(res.error) || 'Unknown error'}`, res);
Expand Down
34 changes: 15 additions & 19 deletions apify-docs-theme/src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ function copyChangelogFromRoot(paths, hasDefaultChangelog, { displayedSidebar }
for (const docsPath of paths) {
const targetChangelogPath = path.join(docsPath, 'changelog.md');

if (fs.existsSync(targetChangelogPath)
&& fs.statSync(targetChangelogPath).mtime >= fs.statSync(sourceChangelogPath).mtime
&& !hasDefaultChangelog.get(docsPath)) {
if (
fs.existsSync(targetChangelogPath) &&
fs.statSync(targetChangelogPath).mtime >= fs.statSync(sourceChangelogPath).mtime &&
!hasDefaultChangelog.get(docsPath)
) {
continue;
}

Expand All @@ -61,10 +63,7 @@ function copyChangelogFromRoot(paths, hasDefaultChangelog, { displayedSidebar }
}
}

function theme(
context,
options,
) {
function theme(context, options) {
return {
name: '@apify/docs-theme',
getPathsToWatch() {
Expand All @@ -81,28 +80,27 @@ function theme(
const versioned = findPathInParent('website/versioned_docs');
const pathsToCopyChangelog = [
findPathInParentOrThrow('docs'),
...(versioned
? fs.readdirSync(versioned).map((version) => path.join(versioned, version))
: []
),
...(versioned ? fs.readdirSync(versioned).map((version) => path.join(versioned, version)) : []),
];

const { changelogDisplayedSidebar: displayedSidebar } = options;
const displayedSidebarLine = displayedSidebar !== undefined
? `displayed_sidebar: ${displayedSidebar}\n`
: '';
const displayedSidebarLine =
displayedSidebar !== undefined ? `displayed_sidebar: ${displayedSidebar}\n` : '';
const hasDefaultChangelog = new Map();

for (const p of pathsToCopyChangelog) {
// the changelog page has to exist for the sidebar to work - async loadContent() is (apparently) not awaited for by sidebar
if (fs.existsSync(path.join(p, 'changelog.md'))) continue;
fs.writeFileSync(`${p}/changelog.md`, `---
fs.writeFileSync(
`${p}/changelog.md`,
`---
title: Changelog
sidebar_label: Changelog
${displayedSidebarLine}---
It seems that the changelog is not available.
This either means that your Docusaurus setup is misconfigured, or that your GitHub repository contains no releases yet.
`);
`,
);
hasDefaultChangelog.set(p, true);
}

Expand All @@ -126,9 +124,7 @@ This either means that your Docusaurus setup is misconfigured, or that your GitH
});
},
getClientModules() {
return [
require.resolve('./theme/custom.css'),
];
return [require.resolve('./theme/custom.css')];
},
configureWebpack() {
return {
Expand Down
41 changes: 14 additions & 27 deletions apify-docs-theme/src/theme/ColorModeToggle/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import IconDarkMode from '../Icon/DarkMode';
import IconLightMode from '../Icon/LightMode';
import styles from './styles.module.css';

function ColorModeToggle({
className,
value,
onChange,
}) {
function ColorModeToggle({ className, value, onChange }) {
const isBrowser = useIsBrowser();
const title = translate(
{
Expand All @@ -23,39 +19,30 @@ function ColorModeToggle({
mode:
value === 'dark'
? translate({
message: 'dark mode',
id: 'theme.colorToggle.ariaLabel.mode.dark',
description: 'The name for the dark color mode',
})
message: 'dark mode',
id: 'theme.colorToggle.ariaLabel.mode.dark',
description: 'The name for the dark color mode',
})
: translate({
message: 'light mode',
id: 'theme.colorToggle.ariaLabel.mode.light',
description: 'The name for the light color mode',
}),
message: 'light mode',
id: 'theme.colorToggle.ariaLabel.mode.light',
description: 'The name for the light color mode',
}),
},
);
return (
<div className={clsx(styles.toggle, className)}>
<button
className={clsx(
'clean-btn',
styles.toggleButton,
!isBrowser && styles.toggleButtonDisabled,
)}
className={clsx('clean-btn', styles.toggleButton, !isBrowser && styles.toggleButtonDisabled)}
type="button"
onClick={() => onChange(value === 'dark' ? 'light' : 'dark')}
disabled={!isBrowser}
title={title}
aria-label={title}>
aria-label={title}
>
<span>
<IconLightMode
className={clsx(styles.toggleIcon, styles.lightToggleIcon)}
width={14} height={14}
/>
<IconDarkMode
className={clsx(styles.toggleIcon, styles.darkToggleIcon)}
width={14} height={14}
/>
<IconLightMode className={clsx(styles.toggleIcon, styles.lightToggleIcon)} width={14} height={14} />
<IconDarkMode className={clsx(styles.toggleIcon, styles.darkToggleIcon)} width={14} height={14} />
</span>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default function HomeBreadcrumbItem() {
description: 'The ARIA label for the home page in the breadcrumbs',
})}
className="breadcrumbs__link"
href={homeHref}>
href={homeHref}
>
<IconHome className={styles.breadcrumbHomeIcon} />
</Link>
</li>
Expand Down
30 changes: 10 additions & 20 deletions apify-docs-theme/src/theme/DocBreadcrumbs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Link from '@docusaurus/Link';
import {
useSidebarBreadcrumbs,
} from '@docusaurus/plugin-content-docs/client';
import { useSidebarBreadcrumbs } from '@docusaurus/plugin-content-docs/client';
import { ThemeClassNames } from '@docusaurus/theme-common';
import { useHomePageRoute } from '@docusaurus/theme-common/internal';
import { translate } from '@docusaurus/Translate';
Expand Down Expand Up @@ -46,9 +44,10 @@ function BreadcrumbsItem({ children, active, index, addMicrodata }) {
})}
className={clsx('breadcrumbs__item', {
'breadcrumbs__item--active': active,
})}>
})}
>
{children}
<meta itemProp="position" content={String(index + 1)}/>
<meta itemProp="position" content={String(index + 1)} />
</li>
);
}
Expand All @@ -61,29 +60,20 @@ export default function DocBreadcrumbs() {
}
return (
<nav
className={clsx(
ThemeClassNames.docs.docBreadcrumbs,
styles.breadcrumbsContainer,
)}
className={clsx(ThemeClassNames.docs.docBreadcrumbs, styles.breadcrumbsContainer)}
aria-label={translate({
id: 'theme.docs.breadcrumbs.navAriaLabel',
message: 'Breadcrumbs',
description: 'The ARIA label for the breadcrumbs',
})}>
<ul
className="breadcrumbs"
itemScope
itemType="https://schema.org/BreadcrumbList">
{homePageRoute && <HomeBreadcrumbItem/>}
})}
>
<ul className="breadcrumbs" itemScope itemType="https://schema.org/BreadcrumbList">
{homePageRoute && <HomeBreadcrumbItem />}
{breadcrumbs.map((item, idx) => {
// const isLast = idx === breadcrumbs.length - 1;
const isLast = false;
return (
<BreadcrumbsItem
key={idx}
active={isLast}
index={idx}
addMicrodata={!!item.href}>
<BreadcrumbsItem key={idx} active={isLast} index={idx} addMicrodata={!!item.href}>
<BreadcrumbsItemLink href={item.href} isLast={isLast}>
{item.label}
</BreadcrumbsItemLink>
Expand Down
Loading
Loading