mirror of
https://gitea.com/gitea/docs.git
synced 2026-07-22 02:37:42 +00:00
Use custom api dropdown and fix compatibility for firefox (#39)
- Used custom api dropdown for changing label dynamically. Used method discussed in [this post](https://github.com/facebook/docusaurus/pull/7231). `ComponentTypes` is ejected safely.  - Fixed dropdowns missing on chrome docs page  - Fixed `:has` selector compatibility problem on firefox. After (Screenshots from firefox):     Reviewed-on: https://gitea.com/gitea/gitea-docusaurus/pulls/39 Co-authored-by: HesterG <hestergong@gmail.com> Co-committed-by: HesterG <hestergong@gmail.com>
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -24,9 +24,9 @@ docs/
|
|||||||
versioned_docs/
|
versioned_docs/
|
||||||
static/_headers
|
static/_headers
|
||||||
static/_redirects
|
static/_redirects
|
||||||
static/latest-swagger.json
|
static/swagger-latest.json
|
||||||
static/19-swagger.json
|
static/swagger-19.json
|
||||||
static/20-swagger.json
|
static/swagger-20.json
|
||||||
i18n/zh-cn/docusaurus-plugin-content-docs/current
|
i18n/zh-cn/docusaurus-plugin-content-docs/current
|
||||||
i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19
|
i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19
|
||||||
i18n/zh-cn/docusaurus-plugin-content-docs/version-1.20
|
i18n/zh-cn/docusaurus-plugin-content-docs/version-1.20
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ function sortItemsByCategory(items) {
|
|||||||
return sortedItems;
|
return sortedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
const includeAPI = process.env.INCLUDE_API !== 'false';
|
const renderApiSSR = process.env.API_SSR !== 'false';
|
||||||
|
|
||||||
const apiConfig = [
|
const apiConfig = [
|
||||||
'redocusaurus',
|
'redocusaurus',
|
||||||
{
|
{
|
||||||
// Plugin Options for loading OpenAPI files
|
// Plugin Options for loading OpenAPI files
|
||||||
specs: includeAPI ? [
|
specs: renderApiSSR ? [
|
||||||
{
|
{
|
||||||
spec: 'static/swagger-latest.json',
|
spec: 'static/swagger-latest.json',
|
||||||
route: '/api/next/',
|
route: '/api/next/',
|
||||||
@@ -41,7 +41,7 @@ const apiConfig = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const pageConfig = includeAPI ? {
|
const pageConfig = renderApiSSR ? {
|
||||||
exclude: [
|
exclude: [
|
||||||
'api/**',
|
'api/**',
|
||||||
],
|
],
|
||||||
@@ -167,15 +167,14 @@ const config = {
|
|||||||
activeBaseRegex: 'api/(1.19|1.20|next)/',
|
activeBaseRegex: 'api/(1.19|1.20|next)/',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'dropdown',
|
type: 'custom-apiDropdown',
|
||||||
label: 'API Version',
|
label: 'API Version',
|
||||||
position: 'right',
|
position: 'right',
|
||||||
items: [
|
items: [
|
||||||
{to: '/api/next/', label: '1.21-dev' },
|
{to: '/api/next/', label: '1.21-dev' },
|
||||||
{to: '/api/1.20/', label: '1.20.0-rc0' },
|
{to: '/api/1.20/', label: '1.20.0-rc2' },
|
||||||
{to: '/api/1.19/', label: '1.19.4' },
|
{to: '/api/1.19/', label: '1.19.4' },
|
||||||
],
|
],
|
||||||
className: 'api-dropdown',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: 'https://github.com/go-gitea/gitea',
|
href: 'https://github.com/go-gitea/gitea',
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"docusaurus": "docusaurus",
|
"docusaurus": "docusaurus",
|
||||||
"start": "docusaurus start",
|
"start": "docusaurus start",
|
||||||
"start-CSRApi": "cross-env INCLUDE_API='false' docusaurus start",
|
"start-CSRApi": "cross-env API_SSR='false' docusaurus start",
|
||||||
"build": "docusaurus build",
|
"build": "docusaurus build",
|
||||||
"build-CSRApi": "cross-env INCLUDE_API='false' docusaurus build",
|
"build-CSRApi": "cross-env API_SSR='false' docusaurus build",
|
||||||
"swizzle": "docusaurus swizzle",
|
"swizzle": "docusaurus swizzle",
|
||||||
"deploy": "docusaurus deploy",
|
"deploy": "docusaurus deploy",
|
||||||
"clear": "docusaurus clear",
|
"clear": "docusaurus clear",
|
||||||
|
|||||||
23
src/components/APIDropDown.js
Normal file
23
src/components/APIDropDown.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
||||||
|
import {useLocation} from '@docusaurus/router';
|
||||||
|
|
||||||
|
export default function APIDropDown(props) {
|
||||||
|
const {pathname} = useLocation();
|
||||||
|
let newLabel = props.label;
|
||||||
|
// isAPI indicates if the current page is a api page
|
||||||
|
let isAPI = false;
|
||||||
|
for (const item of props.items) {
|
||||||
|
// paths like /zh-cn/api/{version}/ are also api pages
|
||||||
|
if (pathname === item.to || pathname === `/zh-cn${item.to}`) {
|
||||||
|
if (!props.mobile) newLabel = item.label;
|
||||||
|
isAPI = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const newProps = {...props, label: newLabel};
|
||||||
|
// Hide api dropdown on non api pages
|
||||||
|
return (
|
||||||
|
<DropdownNavbarItem {...newProps} className={`api-dropdown${isAPI? '': ' gt-hidden'}`}></DropdownNavbarItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -63,52 +63,52 @@
|
|||||||
top: 70px !important;
|
top: 70px !important;
|
||||||
height: calc(100vh - 70px) !important;
|
height: calc(100vh - 70px) !important;
|
||||||
}
|
}
|
||||||
/* The following css is for toggling API version dropdown/menu,
|
|
||||||
selectors like :first-of-type are for browsers those do not support :has */
|
.gt-hidden {
|
||||||
/* Do not show doc search on api pages */
|
|
||||||
body:has(.redocusaurus) [class*='searchBox'],
|
|
||||||
.plugin-redoc [class*='searchBox'],
|
|
||||||
.plugin-pages [class*='searchBox'] {
|
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
/* The following css is for toggling API version dropdown/menu,
|
||||||
@media (min-width: 996px) {
|
TODO: need to find a proper way to customize the classname
|
||||||
/* hide api-dropdown on other pages */
|
*/
|
||||||
.navbar__item.dropdown:not(:has(.api-dropdown)),
|
@supports selector(:has(*)) {
|
||||||
.navbar__item.dropdown:first-of-type {
|
/* Do not show doc search on api pages */
|
||||||
|
body:has(.redocusaurus) [class*='searchBox'] {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
/* show api-dropdown dropdown and hide other dropdowns on api pages */
|
|
||||||
body:has(.redocusaurus) .navbar__item.dropdown:not(:has(.api-dropdown)),
|
@media (min-width: 996px) {
|
||||||
|
/* hide other dropdowns except for api dropdown on api pages */
|
||||||
|
body:has(.redocusaurus) .navbar__item.dropdown:not(:has(.api-dropdown)) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 996px) {
|
||||||
|
/* on mobile, dropdown becomes menu list */
|
||||||
|
/* Hide collapsible menus except for API menu on API pages */
|
||||||
|
body:has(.redocusaurus) .menu__list-item.menu__list-item--collapsed:not(:has(.api-dropdown)) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* selectors like :first-of-type are for browsers those do not support :has */
|
||||||
|
@supports not (selector(:has(*))) {
|
||||||
|
.plugin-redoc [class*='searchBox'],
|
||||||
|
.plugin-pages [class*='searchBox'] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 996px) {
|
||||||
.plugin-redoc .navbar__item.dropdown:not(:first-of-type),
|
.plugin-redoc .navbar__item.dropdown:not(:first-of-type),
|
||||||
.plugin-pages .navbar__item.dropdown:not(:first-of-type) {
|
.plugin-pages .navbar__item.dropdown:not(:first-of-type) {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
body:has(.redocusaurus) .navbar__item.dropdown:has(.api-dropdown),
|
|
||||||
.plugin-redoc .navbar__item.dropdown:first-of-type,
|
|
||||||
.plugin-pages .navbar__item.dropdown:first-of-type {
|
|
||||||
display: block;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 996px) {
|
@media (max-width: 996px) {
|
||||||
/* need to find a way to customize the classname */
|
.plugin-redoc .menu__list-item.menu__list-item--collapsed:not(:nth-of-type(3)),
|
||||||
/* on mobile, dropdown becomes menu list */
|
.plugin-pages .menu__list-item.menu__list-item--collapsed:not(:nth-of-type(3)) {
|
||||||
/* Hide api version menu on other pages */
|
|
||||||
.menu__list-item.menu__list-item--collapsed:has(.api-dropdown),
|
|
||||||
.menu__list-item.menu__list-item--collapsed:nth-of-type(3) {
|
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
/* Hide collapsible menus except for API menu on API pages */
|
|
||||||
body:has(.redocusaurus) .menu__list-item.menu__list-item--collapsed:not(:has(.api-dropdown)),
|
|
||||||
.plugin-redoc .menu__list-item.menu__list-item--collapsed:not(:first-of-type),
|
|
||||||
.plugin-pages .menu__list-item.menu__list-item--collapsed:not(:first-of-type) {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
/* Show collapsible API menu on API pages */
|
|
||||||
body:has(.redocusaurus) .menu__list-item:has(.api-dropdown),
|
|
||||||
.plugin-redoc .menu__list-item:nth-of-type(3),
|
|
||||||
.plugin-pages .menu__list-item:nth-of-type(3) {
|
|
||||||
display: list-item !important;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/theme/NavbarItem/ComponentTypes.js
Normal file
24
src/theme/NavbarItem/ComponentTypes.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
||||||
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
||||||
|
import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
|
||||||
|
import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
||||||
|
import HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
|
||||||
|
import DocNavbarItem from '@theme/NavbarItem/DocNavbarItem';
|
||||||
|
import DocSidebarNavbarItem from '@theme/NavbarItem/DocSidebarNavbarItem';
|
||||||
|
import DocsVersionNavbarItem from '@theme/NavbarItem/DocsVersionNavbarItem';
|
||||||
|
import DocsVersionDropdownNavbarItem from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
|
||||||
|
import APIDropDown from '@site/src/components/APIDropDown';
|
||||||
|
|
||||||
|
const ComponentTypes = {
|
||||||
|
default: DefaultNavbarItem,
|
||||||
|
localeDropdown: LocaleDropdownNavbarItem,
|
||||||
|
search: SearchNavbarItem,
|
||||||
|
dropdown: DropdownNavbarItem,
|
||||||
|
html: HtmlNavbarItem,
|
||||||
|
doc: DocNavbarItem,
|
||||||
|
docSidebar: DocSidebarNavbarItem,
|
||||||
|
docsVersion: DocsVersionNavbarItem,
|
||||||
|
docsVersionDropdown: DocsVersionDropdownNavbarItem,
|
||||||
|
'custom-apiDropdown': APIDropDown,
|
||||||
|
};
|
||||||
|
export default ComponentTypes;
|
||||||
Reference in New Issue
Block a user