Skip to content

Commit

Permalink
Merge branch 'master' into deployment-source-types
Browse files Browse the repository at this point in the history
  • Loading branch information
TC-MO authored Sep 5, 2024
2 parents c9eb560 + 8ccfb9b commit 1acb828
Show file tree
Hide file tree
Showing 79 changed files with 23,952 additions and 11,746 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
- run: gh workflow run deploy.yaml --repo apify/apify-docs-private
env:
GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
SMARTLOOK_PROJECT_KEY: ${{ secrets.SMARTLOOK_PROJECT_KEY }}
INTERCOM_APP_ID: ${{ secrets.INTERCOM_APP_ID }}
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
env:
APIFY_SIGNING_TOKEN: ${{ secrets.APIFY_SIGNING_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
SMARTLOOK_PROJECT_KEY: ${{ secrets.SMARTLOOK_PROJECT_KEY }}
INTERCOM_APP_ID: ${{ secrets.INTERCOM_APP_ID }}

- name: Set up GitHub Pages
uses: actions/configure-pages@v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lychee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
env:
APIFY_SIGNING_TOKEN: ${{ secrets.APIFY_SIGNING_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
SMARTLOOK_PROJECT_KEY: ${{ secrets.SMARTLOOK_PROJECT_KEY }}
INTERCOM_APP_ID: ${{ secrets.INTERCOM_APP_ID }}

- name: Run Lychee Link Checker
id: lychee
Expand Down
18 changes: 7 additions & 11 deletions .github/workflows/publish-theme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
workflow_dispatch:

jobs:
look_for_change:
Expand All @@ -23,15 +24,15 @@ jobs:

- name: Check changes in theme
id: changed-theme-files
uses: tj-actions/changed-files@v44
uses: tj-actions/changed-files@v45
with:
since_last_remote_commit: "true"
files: |
apify-docs-theme/**
publish:
needs: look_for_change
if: needs.look_for_change.outputs.theme_changed == 'true'
if: ${{ needs.look_for_change.outputs.theme_changed == 'true' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -45,32 +46,27 @@ jobs:
cache: 'npm'
cache-dependency-path: 'package-lock.json'
always-auth: 'true'
registry-url: 'https://npm.pkg.github.com/'
scope: '@apify-packages'
env:
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}

- name: Setup git user and npm
run: |
git config --global user.name "Apify Release Bot"
git config --global user.email "noreply@apify.com"
echo "access=public" > .npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}" >> .npmrc
echo "access=public" > ~/.npmrc
echo "@apify-packages:registry=https://npm.pkg.github.com/" >> ~/.npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}" >> ~/.npmrc
- name: Bump the theme version
run: |
cd $GITHUB_WORKSPACE/apify-docs-theme
npm version patch --legacy-peer-deps
env:
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
- name: Deploy theme to npm
run: |
cd $GITHUB_WORKSPACE/apify-docs-theme
npx -y publish-if-not-exists
env:
NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
GIT_USER: "barjin:${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}"
GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- run: npm run build
env:
SMARTLOOK_PROJECT_KEY: ${{ secrets.SMARTLOOK_PROJECT_KEY }}
INTERCOM_APP_ID: ${{ secrets.INTERCOM_APP_ID }}

lint_content:
name: Lint markdown content
Expand All @@ -41,7 +41,7 @@ jobs:

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44.5.7
uses: tj-actions/changed-files@v45
with:
files: |
**/*.md
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44.5.7
uses: tj-actions/changed-files@v45
with:
files: |
**/*.{md,mdx}
Expand Down
3 changes: 2 additions & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"link-fragments": false,
"no-duplicate-heading": {
"siblings_only": true
}
},
"no-bare-urls": false
}
7 changes: 3 additions & 4 deletions apify-docs-theme/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apify/docs-theme",
"version": "1.0.128",
"version": "1.0.133",
"description": "",
"main": "./src/index.js",
"files": [
Expand All @@ -19,13 +19,12 @@
"access": "public"
},
"dependencies": {
"@apify/docs-search-modal": "^1.0.26",
"@docusaurus/theme-common": "^2.4.1",
"@apify/docs-search-modal": "^1.1.0",
"@docusaurus/theme-common": "^3.5.2",
"@stackql/docusaurus-plugin-hubspot": "^1.1.0",
"axios": "^1.7.4",
"babel-loader": "^9.1.3",
"docusaurus-gtm-plugin": "^0.0.2",
"docusaurus-plugin-smartlook": "^1.0.2",
"postcss-preset-env": "^9.3.0",
"prism-react-renderer": "^2.0.6"
},
Expand Down
2 changes: 0 additions & 2 deletions apify-docs-theme/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const themeConfig = ({
hideable: true,
},
},
smartlook: { projectKey: process.env.SMARTLOOK_PROJECT_KEY || '-' },
navbar: {
title: 'Apify Docs',
logo: {
Expand Down Expand Up @@ -266,7 +265,6 @@ const themeConfig = ({
});

const plugins = [
'docusaurus-plugin-smartlook',
[
'docusaurus-gtm-plugin',
{
Expand Down
21 changes: 15 additions & 6 deletions apify-docs-theme/src/markdown.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
function updateChangelog(changelog) {
changelog = addHeader(changelog);
changelog = addFrontmatter(changelog);
changelog = pushHeadings(changelog);
changelog = linkUsers(changelog);
changelog = linkPRs(changelog);
changelog = fixUserLinks(changelog);
changelog = fixPRLinks(changelog);
changelog = escapeMDXCharacters(changelog);
return changelog;
}

function addHeader(changelog, header = 'Changelog') {
function addFrontmatter(changelog, header = 'Changelog') {
return `---
title: ${header}
sidebar_label: ${header}
Expand All @@ -19,14 +20,22 @@ function pushHeadings(changelog) {
return changelog.replaceAll(/\n#[^#]/g, '\n## ');
}

function linkUsers(changelog) {
function fixUserLinks(changelog) {
return changelog.replaceAll(/by @([a-zA-Z0-9-]+)/g, 'by [@$1](https://github.com/$1)');
}

function linkPRs(changelog) {
function fixPRLinks(changelog) {
return changelog.replaceAll(/(((https?:\/\/)?(www.)?)?github.com\/[^\s]*?\/pull\/([0-9]+))/g, '[#$5]($1)');
}

function escapeMDXCharacters(changelog) {
return changelog.replaceAll(/<|>/g, (match) => {
return match === '<' ? '&lt;' : '&gt;';
}).replaceAll(/\{|\}/g, (match) => {
return match === '{' ? '&#123;' : '&#125;';
});
}

module.exports = {
updateChangelog,
};
29 changes: 19 additions & 10 deletions apify-docs-theme/src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function findPathInParentOrThrow(endPath) {
return filePath;
}

async function copyChangelogFromReleases(paths, repo) {
async function generateChangelogFromGitHubReleases(paths, repo) {
const response = await axios.get(`https://api.github.com/repos/${repo}/releases`);
const releases = response.data;

Expand All @@ -40,18 +40,24 @@ async function copyChangelogFromReleases(paths, repo) {
});

paths.forEach((p) => {
fs.writeFileSync(`${p}/changelog.md`, updateChangelog(markdown));
fs.writeFileSync(path.join(p, 'changelog.md'), updateChangelog(markdown));
});
}

function copyChangelogFromRoot(paths) {
const changelogPath = findPathInParentOrThrow('CHANGELOG.md');
function copyChangelogFromRoot(paths, hasDefaultChangelog) {
const sourceChangelogPath = findPathInParentOrThrow('CHANGELOG.md');

for (const docsPath of paths) {
if (fs.existsSync(path.join(docsPath, 'changelog.md')) && fs.statSync(
path.join(docsPath, 'changelog.md')).mtime >= fs.statSync(changelogPath).mtime) continue;
const changelog = fs.readFileSync(changelogPath, 'utf-8');
fs.writeFileSync(`${docsPath}/changelog.md`, updateChangelog(changelog));
const targetChangelogPath = path.join(docsPath, 'changelog.md');

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

const changelog = fs.readFileSync(sourceChangelogPath, 'utf-8');
fs.writeFileSync(targetChangelogPath, updateChangelog(changelog));
}
}

Expand Down Expand Up @@ -81,6 +87,8 @@ function theme(
),
];

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;
Expand All @@ -91,12 +99,13 @@ sidebar_label: Changelog
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);
}

if (options.changelogFromRoot) {
copyChangelogFromRoot(pathsToCopyChangelog);
copyChangelogFromRoot(pathsToCopyChangelog, hasDefaultChangelog);
} else {
await copyChangelogFromReleases(pathsToCopyChangelog, `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`);
await generateChangelogFromGitHubReleases(pathsToCopyChangelog, `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`);
}
} catch (e) {
// eslint-disable-next-line no-console
Expand Down
6 changes: 3 additions & 3 deletions apify-docs-theme/src/theme/DocBreadcrumbs/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Link from '@docusaurus/Link';
import { ThemeClassNames } from '@docusaurus/theme-common';
import {
useSidebarBreadcrumbs,
useHomePageRoute,
} from '@docusaurus/theme-common/internal';
} from '@docusaurus/plugin-content-docs/client';
import { ThemeClassNames } from '@docusaurus/theme-common';
import { useHomePageRoute } from '@docusaurus/theme-common/internal';
import { translate } from '@docusaurus/Translate';
import HomeBreadcrumbItem from '@theme/DocBreadcrumbs/Items/Home';
import clsx from 'clsx';
Expand Down
2 changes: 1 addition & 1 deletion apify-docs-theme/src/theme/DocSidebarItem/Link/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import clsx from 'clsx';
import { ThemeClassNames } from '@docusaurus/theme-common';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import { isActiveSidebarItem } from '@docusaurus/theme-common/internal';
import { isActiveSidebarItem } from '@docusaurus/plugin-content-docs/client';
import Link from '@docusaurus/Link';
import isInternalUrl from '@docusaurus/isInternalUrl';
import IconExternalLink from '@theme/Icon/ExternalLink';
Expand Down
14 changes: 0 additions & 14 deletions apify-docs-theme/src/theme/MDXComponents/Pre.js

This file was deleted.

2 changes: 1 addition & 1 deletion apify-docs-theme/src/theme/NavbarItem/ComponentTypes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
import DocSidebarNavbarItem from '@theme/NavbarItem/DocSidebarNavbarItem';
import DocsVersionNavbarItem from '@theme/NavbarItem/DocsVersionNavbarItem';
import DocsVersionDropdownNavbarItem from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
import { useDocsVersion, useLayoutDoc } from '@docusaurus/theme-common/internal';
import { useDocsVersion, useLayoutDoc } from '@docusaurus/plugin-content-docs/client';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import React from 'react';

Expand Down
9 changes: 8 additions & 1 deletion apify-docs-theme/src/theme/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@ html[data-theme='dark'] .runnable-code-block svg .apify-logo {
.prism-code.language-python .token-line::before,
.prism-code.language-dockerfile .token-line::before,
.prism-code.language-XML .token-line::before,
.prism-code.language-yaml .token-line::before,
.prism-code.language-js .token-line::before {
counter-increment: line-number;
content: counter(line-number);
Expand All @@ -1560,7 +1561,6 @@ html[data-theme='dark'] .runnable-code-block svg .apify-logo {
min-width: 1.5rem;
display: inline-block;
opacity: .3;
position: sticky;
left: var(--ifm-pre-padding);
}

Expand All @@ -1579,3 +1579,10 @@ html[data-theme='dark'] .runnable-code-block svg .apify-logo {
.apiPage .tsd-panel-header .tsd-anchor-id {
top: -13rem;
}

iframe[src*="youtube"] {
width: 100%;
aspect-ratio: 16/9;
height: auto;
margin-bottom: 1.6rem;
}
Binary file modified apify-docs-theme/static/img/favicon.ico
Binary file not shown.
Loading

0 comments on commit 1acb828

Please sign in to comment.