Skip to content

Commit

Permalink
feat(nextra): ✨ update to latest nextra updates
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Feb 23, 2022
1 parent 6f959a6 commit 1adc3b0
Show file tree
Hide file tree
Showing 12 changed files with 301 additions and 237 deletions.
125 changes: 57 additions & 68 deletions .yalc/nextra-renderlesskit-theme-docs/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ function useMenuContext() {

// src/utils/normalize-pages.tsx
import getTitle from "title";

// src/misc/theme-context.tsx
var themeContext = {
navbar: true,
sidebar: true,
toc: true,
pagination: true,
footer: true,
full: false
};
var theme_context_default = themeContext;

// src/utils/normalize-pages.tsx
function getMetaTitle(meta) {
if (typeof meta === "string")
return meta;
Expand All @@ -373,7 +386,7 @@ function getMetaTitle(meta) {
function getMetaItemType(meta) {
if (typeof meta === "object")
return meta.type;
return "docs";
return "doc";
}
function getMetaHidden(meta) {
if (typeof meta === "object")
Expand All @@ -385,7 +398,8 @@ function normalizePages({
locale,
defaultLocale,
route,
docsRoot = ""
docsRoot = "",
pageThemeContext = theme_context_default
}) {
let meta = "";
for (let item of list) {
Expand Down Expand Up @@ -415,6 +429,7 @@ function normalizePages({
const flatPageDirectories = [];
let activeType = void 0;
let activeIndex = 0;
let activeThemeContext = pageThemeContext;
list.filter((a) => a.name !== "meta.json" && !a.name.startsWith("_") && (a.locale === locale || (a.locale === defaultLocale || !a.locale) && !hasLocale.get(a.name))).sort((a, b) => {
const indexA = metaKeys.indexOf(a.name);
const indexB = metaKeys.indexOf(b.name);
Expand All @@ -426,19 +441,21 @@ function normalizePages({
return -1;
return indexA - indexB;
}).forEach((a) => {
var _a;
if (typeof meta !== "object")
return;
const title = getMetaTitle(meta[a.name]) || getTitle(a.name);
const type = getMetaItemType(meta[a.name]) || "docs";
const type = getMetaItemType(meta[a.name]) || "doc";
const hidden = getMetaHidden(meta[a.name]);
const isCurrentDocsTree = type === "docs" && route.startsWith(docsRoot);
const extendedPageThemeContext = __spreadValues(__spreadValues({}, pageThemeContext), (_a = meta[a.name]) == null ? void 0 : _a.theme);
const isCurrentDocsTree = type === "doc" && route.startsWith(docsRoot);
if (a.route === route) {
activeType = type;
switch (type) {
case "nav":
case "page":
activeIndex = flatPageDirectories.length;
break;
case "docs":
case "doc":
default:
if (isCurrentDocsTree) {
activeIndex = flatDocsDirectories.length;
Expand All @@ -454,12 +471,13 @@ function normalizePages({
}) : void 0;
if (normalizedChildren) {
if (normalizedChildren.activeIndex !== void 0 && normalizedChildren.activeType !== void 0) {
activeThemeContext = extendedPageThemeContext;
activeType = normalizedChildren.activeType;
switch (activeType) {
case "nav":
case "page":
activeIndex = flatPageDirectories.length + normalizedChildren.activeIndex;
break;
case "docs":
case "doc":
activeIndex = flatDocsDirectories.length + normalizedChildren.activeIndex;
break;
}
Expand All @@ -483,15 +501,15 @@ function normalizePages({
});
if (normalizedChildren) {
switch (type) {
case "nav":
case "page":
pageItem.children.push(...normalizedChildren.pageDirectories);
docsDirectories.push(...normalizedChildren.docsDirectories);
if (!normalizedChildren.flatPageDirectories.length && normalizedChildren.flatDirectories.length) {
pageItem.firstChildRoute = normalizedChildren.flatDirectories[0].route;
flatPageDirectories.push(pageItem);
}
break;
case "docs":
case "doc":
default:
if (isCurrentDocsTree) {
Array.isArray(docsItem.children) && docsItem.children.push(...normalizedChildren.docsDirectories);
Expand All @@ -505,10 +523,10 @@ function normalizePages({
} else {
flatDirectories.push(item);
switch (type) {
case "nav":
case "page":
flatPageDirectories.push(pageItem);
break;
case "docs":
case "doc":
default:
if (isCurrentDocsTree) {
flatDocsDirectories.push(docsItem);
Expand All @@ -517,10 +535,10 @@ function normalizePages({
}
directories.push(item);
switch (type) {
case "nav":
case "page":
pageDirectories.push(pageItem);
break;
case "docs":
case "doc":
default:
if (isCurrentDocsTree) {
docsDirectories.push(docsItem);
Expand All @@ -530,6 +548,7 @@ function normalizePages({
return {
activeType,
activeIndex,
activeThemeContext,
directories,
flatDirectories,
docsDirectories,
Expand Down Expand Up @@ -1176,7 +1195,7 @@ import React19, {
useState as useState3
} from "react";
import cn4 from "classnames";
import { matchSorter } from "match-sorter";
import matchSorter from "match-sorter";
import Link4 from "next/link";
import { useRouter as useRouter4 } from "next/router";
var Item2 = ({ title, active, href, onMouseOver, search }) => {
Expand Down Expand Up @@ -1717,9 +1736,14 @@ function useDirectoryInfo(pageMap) {
});
}, [pageMap, locale, defaultLocale, asPath]);
}
var Body = ({ meta, toc, navLinks, children }) => {
return /* @__PURE__ */ React23.createElement(React23.Fragment, null, /* @__PURE__ */ React23.createElement(SkipNavContent, null), meta.full ? /* @__PURE__ */ React23.createElement("article", {
className: "relative w-full overflow-x-hidden"
var Body = ({
themeContext: themeContext2,
toc,
navLinks,
children
}) => {
return /* @__PURE__ */ React23.createElement(React23.Fragment, null, /* @__PURE__ */ React23.createElement(SkipNavContent, null), themeContext2.full ? /* @__PURE__ */ React23.createElement("article", {
className: cn8("full relative overflow-x-hidden", !themeContext2.sidebar ? "expand" : "")
}, /* @__PURE__ */ React23.createElement(MDXTheme, null, children)) : /* @__PURE__ */ React23.createElement("article", {
className: "docs-container relative pb-8 w-full max-w-full flex min-w-0 pr-[calc(env(safe-area-inset-right)-1.5rem)]"
}, /* @__PURE__ */ React23.createElement("main", {
Expand All @@ -1739,6 +1763,7 @@ var Layout = ({
const {
activeType,
activeIndex,
activeThemeContext,
flatPageDirectories,
docsDirectories,
flatDirectories,
Expand All @@ -1755,44 +1780,7 @@ var Layout = ({
return localeConfig && localeConfig.direction === "rtl";
}, [config.i18n, locale]);
const [menu, setMenu] = useState6(false);
if (activeType === "nav") {
return /* @__PURE__ */ React23.createElement(React23.Fragment, null, /* @__PURE__ */ React23.createElement(Head, {
title,
locale,
meta
}), /* @__PURE__ */ React23.createElement(MenuContext.Provider, {
value: {
menu,
setMenu,
defaultMenuCollapsed: !!config.defaultMenuCollapsed
}
}, /* @__PURE__ */ React23.createElement("div", {
className: cn8("nextra-container main-container flex flex-col", {
rtl: isRTL,
page: true
})
}, /* @__PURE__ */ React23.createElement(Navbar, {
isRTL,
flatDirectories,
flatPageDirectories
}), /* @__PURE__ */ React23.createElement(ActiveAnchor, null, /* @__PURE__ */ React23.createElement("div", {
className: "max-w-[90rem] w-full mx-auto"
}, /* @__PURE__ */ React23.createElement("div", {
className: "flex flex-1 h-full"
}, /* @__PURE__ */ React23.createElement(Sidebar, {
directories: flatPageDirectories,
flatDirectories,
fullDirectories: directories,
headings,
isRTL,
asPopover: true
}), /* @__PURE__ */ React23.createElement(Body, {
meta,
navLinks: null
}, children)))), config.footer ? /* @__PURE__ */ React23.createElement(footer_default, {
menu: true
}) : null)));
}
const themeContext2 = __spreadValues(__spreadValues({}, activeThemeContext), meta);
return /* @__PURE__ */ React23.createElement(React23.Fragment, null, /* @__PURE__ */ React23.createElement(Head, {
title,
locale,
Expand All @@ -1807,33 +1795,34 @@ var Layout = ({
className: cn8("nextra-container main-container flex flex-col", {
rtl: isRTL
})
}, /* @__PURE__ */ React23.createElement(Navbar, {
}, themeContext2.navbar ? /* @__PURE__ */ React23.createElement(Navbar, {
isRTL,
flatDirectories,
flatPageDirectories
}), /* @__PURE__ */ React23.createElement(ActiveAnchor, null, /* @__PURE__ */ React23.createElement("div", {
}) : null, /* @__PURE__ */ React23.createElement(ActiveAnchor, null, /* @__PURE__ */ React23.createElement("div", {
className: "max-w-[90rem] w-full mx-auto"
}, /* @__PURE__ */ React23.createElement("div", {
className: "flex flex-1 h-full"
}, /* @__PURE__ */ React23.createElement(Sidebar, {
}, themeContext2.sidebar ? /* @__PURE__ */ React23.createElement(Sidebar, {
directories: docsDirectories,
flatDirectories,
fullDirectories: directories,
headings,
isRTL
}), /* @__PURE__ */ React23.createElement(Body, {
meta,
toc: /* @__PURE__ */ React23.createElement(ToC, {
isRTL,
asPopover: activeType === "page"
}) : null, /* @__PURE__ */ React23.createElement(Body, {
themeContext: themeContext2,
toc: activeType === "page" ? null : themeContext2.toc ? /* @__PURE__ */ React23.createElement(ToC, {
headings: config.floatTOC ? headings : null,
filepathWithName
}),
navLinks: /* @__PURE__ */ React23.createElement(NavLinks, {
}) : null,
navLinks: activeType === "page" ? null : themeContext2.pagination ? /* @__PURE__ */ React23.createElement(NavLinks, {
flatDirectories: flatDocsDirectories,
currentIndex: activeIndex,
isRTL
})
}, children)))), config.footer ? /* @__PURE__ */ React23.createElement(footer_default, {
menu: false
}) : null
}, children)))), themeContext2.footer && config.footer ? /* @__PURE__ */ React23.createElement(footer_default, {
menu: activeType === "page" || !themeContext2.sidebar
}) : null)));
};
var src_default = (opts, config) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export declare const themeContext: {
navbar: boolean;
sidebar: boolean;
toc: boolean;
pagination: boolean;
footer: boolean;
full: boolean;
navbar: boolean;
sidebar: boolean;
toc: boolean;
pagination: boolean;
footer: boolean;
full: boolean;
};
export default themeContext;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PageMapItem } from "nextra";
import defaultThemeContext from "../misc/theme-context";
export interface Item extends Omit<PageMapItem, "children"> {
title: string;
type: string;
Expand All @@ -17,15 +18,17 @@ export interface DocsItem extends Omit<PageMapItem, "children"> {
children?: DocsItem[];
firstChildRoute?: string;
}
export default function normalizePages({ list, locale, defaultLocale, route, docsRoot, }: {
export default function normalizePages({ list, locale, defaultLocale, route, docsRoot, pageThemeContext, }: {
list: PageMapItem[];
locale?: string;
defaultLocale?: string;
route: string;
docsRoot?: string;
pageThemeContext?: Record<keyof typeof defaultThemeContext, boolean>;
}): {
activeType: undefined;
activeIndex: number;
activeThemeContext: Record<"footer" | "navbar" | "sidebar" | "toc" | "pagination" | "full", boolean>;
directories: Item[];
flatDirectories: Item[];
docsDirectories: DocsItem[];
Expand Down
2 changes: 1 addition & 1 deletion .yalc/nextra-renderlesskit-theme-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@
"emoji": "emoji",
"editor": false
},
"yalcSig": "58d9a2d568bf33edb5057305bc8dcaf3"
"yalcSig": "49de63f0f6424349937349efd1d707d7"
}
8 changes: 8 additions & 0 deletions .yalc/nextra-renderlesskit-theme-docs/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ blockquote:not(:first-child),

/* Content Typography */
article {
&.full {
width: 100%;
min-height: calc(100vh - 64px);
&.expand {
width: 100vw;
margin: 0 calc(50% - 50vw);
}
}
h1 {
@apply text-4xl font-bold tracking-tight mt-2;
}
Expand Down
2 changes: 1 addition & 1 deletion .yalc/nextra-renderlesskit-theme-docs/yalc.sig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
58d9a2d568bf33edb5057305bc8dcaf3
49de63f0f6424349937349efd1d707d7
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
]
},
"dependencies": {
"@chakra-ui/hooks": "1.8.2",
"@chakra-ui/hooks": "1.8.4",
"@renderlesskit/react-tailwind": "0.0.1-alpha.38",
"lodash": "4.17.21",
"next": "12.0.10",
"nextra": "2.0.0-alpha.24",
"next": "12.1.0",
"nextra": "2.0.0-alpha.28",
"nextra-renderlesskit-theme-docs": "link:.yalc/nextra-renderlesskit-theme-docs",
"react": "17.0.2",
"react-dom": "17.0.2",
Expand All @@ -68,25 +68,25 @@
"twind": "^0.16.16"
},
"devDependencies": {
"@babel/core": "7.17.4",
"@babel/core": "7.17.5",
"@commitlint/cli": "16.2.1",
"@commitlint/config-conventional": "16.2.1",
"@next/eslint-plugin-next": "12.0.10",
"@next/eslint-plugin-next": "12.1.0",
"@release-it/conventional-changelog": "4.1.0",
"@testing-library/dom": "8.11.3",
"@testing-library/jest-dom": "5.16.2",
"@testing-library/react": "12.1.3",
"@testing-library/user-event": "13.5.0",
"@types/jest": "27.4.0",
"@types/jest": "27.4.1",
"@types/lodash": "4.14.178",
"@types/node": "17.0.18",
"@types/node": "17.0.19",
"@types/react": "17.0.39",
"@types/react-dom": "17.0.11",
"all-contributors-cli": "6.20.0",
"autoprefixer": "10.4.2",
"babel-jest": "27.5.1",
"eslint": "8.9.0",
"eslint-config-prettier": "8.3.0",
"eslint-config-prettier": "8.4.0",
"eslint-config-react-app": "7.0.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-simple-import-sort": "7.0.0",
Expand All @@ -98,7 +98,7 @@
"prettier": "2.5.1",
"prettier-plugin-tailwindcss": "0.1.7",
"react-icons": "4.3.1",
"release-it": "14.12.4",
"release-it": "14.12.5",
"sort-package-json": "1.54.0",
"tailwindcss": "3.0.23",
"typescript": "4.5.5"
Expand Down
5 changes: 0 additions & 5 deletions pages/index.md

This file was deleted.

Loading

1 comment on commit 1adc3b0

@vercel
Copy link

@vercel vercel bot commented on 1adc3b0 Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.