Skip to content

Commit

Permalink
feat: switch new OpenAPI docs to /api/v2 (#1411)
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan authored Jan 14, 2025
1 parent cbc8ae9 commit 3ae5eaa
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 54 deletions.
45 changes: 0 additions & 45 deletions apify-api/scripts/script-requirements.txt

This file was deleted.

16 changes: 16 additions & 0 deletions apify-docs-theme/src/theme/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,7 @@ iframe[src*="youtube"] {
justify-content: start;
}

.openapi-endpoint.api-method::before,
.api-method > .menu__link::before,
.schema > .menu__link::before {
width: 55px;
Expand Down Expand Up @@ -1726,73 +1727,88 @@ iframe[src*="youtube"] {
}

.get > .menu__link::before,
.openapi-endpoint.api-method.get::before,
.theme-api-markdown .openapi__method-endpoint .badge--primary {
background-color: var(--ifm-color-info-contrast-background);
color: var(--ifm-color-info-contrast-foreground);
border-color: var(--ifm-color-info-dark);
}

.openapi-endpoint.api-method.get::before,
.get > .menu__link::before {
content: 'get';
}

.openapi-endpoint.api-method.post::before,
.post > .menu__link::before {
content: 'post';
}

.post > .menu__link::before,
.openapi-endpoint.api-method.post::before,
.theme-api-markdown .openapi__method-endpoint .badge--success {
background-color: var(--ifm-color-success-contrast-background);
color: var(--ifm-color-success-contrast-foreground);
border-color: var(--ifm-color-success-dark);
}

.openapi-endpoint.api-method.delete::before,
.delete > .menu__link::before {
content: 'del';
}

.delete > .menu__link::before,
.openapi-endpoint.api-method.delete::before,
.theme-api-markdown .openapi__method-endpoint .badge--danger {
background-color: var(--ifm-color-danger-contrast-background);
color: var(--ifm-color-danger-contrast-foreground);
border-color: var(--ifm-color-danger-dark);
}

.openapi-endpoint.api-method.put::before,
.put > .menu__link::before {
content: 'put';
}

.put > .menu__link::before,
.openapi-endpoint.api-method.put::before,
.theme-api-markdown .openapi__method-endpoint .badge--info {
background-color: var(--ifm-color-warning-contrast-background);
color: var(--ifm-color-warning-contrast-foreground);
border-color: var(--ifm-color-warning-dark);
}

.openapi-endpoint.api-method.patch::before,
.patch > .menu__link::before {
content: 'patch';
}

.patch > .menu__link::before,
.openapi-endpoint.api-method.patch::before,
.theme-api-markdown .openapi__method-endpoint .badge--warning {
background-color: var(--ifm-color-success-contrast-background);
color: var(--ifm-color-success-contrast-foreground);
border-color: var(--ifm-color-success-dark);
}

.openapi-endpoint.api-method.head::before,
.head > .menu__link::before {
content: 'head';
}

.head > .menu__link::before,
.openapi-endpoint.api-method.head::before,
.event > .menu__link::before,
.openapi-endpoint.api-method.event::before,
.schema > .menu__link::before,
.openapi-endpoint.api-method.schema::before,
.theme-api-markdown .openapi__method-endpoint .badge--secondary {
background-color: var(--ifm-color-secondary-contrast-background);
color: var(--ifm-color-secondary-contrast-foreground);
border-color: var(--ifm-color-secondary-dark);
}

.openapi-endpoint.api-method.event::before,
.event > .menu__link::before {
content: 'event';
}
Expand Down
4 changes: 2 additions & 2 deletions apify-docs-theme/static/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ function scrollOpenApiSidebarItemIntoView() {
function redirectOpenApiDocs() {
const { hash, pathname, origin } = new URL(window.location.href);

// TODO change to '/api/v2'
if (pathname.replace(/\/$/, '') !== '/api/v2-new') {
if (!pathname.startsWith('/api/v2') || pathname.startsWith('/api/v2-')) {
return;
}

Expand Down Expand Up @@ -129,5 +128,6 @@ window.addEventListener('load', () => {
});

window.addEventListener('popstate', () => {
setTimeout(() => redirectOpenApiDocs(), 50);
setTimeout(() => scrollOpenApiSidebarItemIntoView(), 50);
});
4 changes: 2 additions & 2 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module.exports = {
specs: [
{
spec: './apify-api/openapi/openapi.yaml',
route: '/api/v2/',
route: '/api/v2-redoc/',
},
],
theme: {
Expand Down Expand Up @@ -177,7 +177,7 @@ module.exports = {
{
id: 'openapi',
path: './sources/api',
routeBasePath: 'api/v2-new', // TODO change to `api/v2` once we are ready
routeBasePath: 'api/v2',
rehypePlugins: [externalLinkProcessor],
showLastUpdateAuthor: false,
showLastUpdateTime: false,
Expand Down
18 changes: 15 additions & 3 deletions src/theme/DocCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function CardContainer({ href, children }) {
);
}

function CardLayout({ href, icon, title, description }) {
function CardLayout({ href, icon, title, description, className }) {
if (href.startsWith('/api')) {
description = '';
}
Expand All @@ -45,7 +45,7 @@ function CardLayout({ href, icon, title, description }) {
href={href}>
<Heading
as="h2"
className={clsx('text--truncate', styles.cardTitle)}
className={clsx('text--truncate', styles.cardTitle, className)}
title={title}>
{icon} {title}
</Heading>
Expand Down Expand Up @@ -78,8 +78,20 @@ function CardCategory({ item }) {
}

function CardLink({ item }) {
const icon = isInternalUrl(item.href) ? '📄️' : '🔗';
const doc = useDocById(item.docId ?? undefined);

if (item.href.startsWith('/api/v2')) {
return (
<CardLayout
href={item.href}
title={item.label}
className={clsx('openapi-endpoint', item.className)}
description={item.description ?? doc?.description}
/>
);
}

const icon = isInternalUrl(item.href) ? '📄️' : '🔗';
return (
<CardLayout
href={item.href}
Expand Down
2 changes: 1 addition & 1 deletion src/theme/DocSidebarItem/Category/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default function DocSidebarItemCategory({ item, onItemClick, activePath,
}
}

console.log(item);
// console.log('sidebar category', item);

return (
<li
Expand Down
2 changes: 1 addition & 1 deletion static/robots.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
User-agent: *
Sitemap: https://docs.apify.com/sitemap.xml
Disallow: https://docs.apify.com/api/v2-old
Disallow: https://docs.apify.com/api/v2-new
Disallow: https://docs.apify.com/api/v2-redoc

0 comments on commit 3ae5eaa

Please sign in to comment.