Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#111]: Backport changes from ecosystem #161

Merged
merged 8 commits into from
Sep 14, 2022
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
2 changes: 1 addition & 1 deletion site/content/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const config = {
title: 'Flowershow',
navbarTitle: { version: true },
Copy link
Member

Choose a reason for hiding this comment

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

surely navbarTitle is something like:

{
	title: 'Flowershow',
	logo: ...
	version: 'Alpha'
}

analytics: 'G-RQWLTRWBS2',
navLinks: [
{ href: '/#overview', name: 'Overview' },
Expand Down
3 changes: 3 additions & 0 deletions templates/default/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_DOCSEARCH_APP_ID=R2IYF7ETH7
NEXT_PUBLIC_DOCSEARCH_API_KEY=599cec31baffa4868cae4e79f180729b
NEXT_PUBLIC_DOCSEARCH_INDEX_NAME=docsearch
43 changes: 31 additions & 12 deletions templates/default/components/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@ function GitHubIcon(props) {
);
}

function NavbarTitle() {
// include option to define different text from title (if needed) in config
const title = siteConfig.navbarTitle?.text || siteConfig.title
Copy link
Member

Choose a reason for hiding this comment

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

Personally, i would be strict and say if you use navbarTitle you have to set title in their too i.e. this is:

if (navbarTitle) {
	use stuff from navbarTitle
} else {
      use siteConfig.title
}

Why? Explicitness is better than magic!

/**
* Navbar logo will not show if:
* - the authorLogo is not defined, or
* - explicitly set to false in config's navbarTitle logo property.
* In all other cases the logo is shown by default.
*/
const logo = (siteConfig.navbarTitle?.logo === false ? false : siteConfig.authorLogo) && siteConfig.authorLogo

return (
<>
<Link href="/" aria-label="Home page">
<a className="flex items-center font-extrabold text-xl sm:text-2xl text-slate-900 dark:text-white">
{logo && <img src={logo} alt={title} className="w-9 h-9 mr-1 fill-white" />}
{title}
</a>
</Link>
{siteConfig.navbarTitle?.version &&
(
<div className="mx-4 rounded-full border border-slate-500 py-1 px-3 text-xs text-slate-500">
{siteConfig.version}
</div>
)
}
</>
)
}

export default function Header() {
const router = useRouter();
const [isScrolled, setIsScrolled] = useState(false);
Expand Down Expand Up @@ -42,18 +72,7 @@ export default function Header() {
<MobileNavigation navigation={siteConfig.navLinks} />
</div>
<div className="flex flex-none items-center">
<Link href="/" aria-label="Home page">
<a className="flex items-center font-extrabold text-xl sm:text-2xl text-slate-900 dark:text-white">
<img src="/assets/images/logo.svg" alt="" className="w-9 h-9 mr-1 fill-white" />
{siteConfig.author}
</a>
</Link>
{siteConfig.version
&& (
<div className="mx-4 rounded-full border border-slate-500 py-1 px-3 text-xs text-slate-500">
{siteConfig.version}
</div>
)}
<NavbarTitle />
<div className="hidden lg:flex ml-8 mr-6 sm:mr-8 md:mr-0">
{siteConfig.navLinks.map((item) => (
<Link key={item.href} href={item.href}>
Expand Down
2 changes: 2 additions & 0 deletions templates/default/components/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export function Search(props) {
);
}, []);

if (!docSearchConfig.appId && !docSearchConfig.apiKey && !docSearchConfig.indexName) return null

return (
<>
<button
Expand Down
2 changes: 2 additions & 0 deletions templates/default/components/ThemeSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function ThemeSelector() {
*/
if (!mounted) return null;

if (!siteConfig.theme.default) return null

return (
<button
className={`
Expand Down
15 changes: 12 additions & 3 deletions templates/default/config/siteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const defaultConfig = {
description: 'Publish your digital garden',
author: 'Flowershow',
// logo image
authorLogo: '/assets/images/logo.svg',
authorLogo: '/_flowershow/logo.svg',
// url to author
authorUrl: 'https://flowershow.app/',
// Google analytics key e.g. G-XXXX
Expand All @@ -20,13 +20,22 @@ const defaultConfig = {
// Theme
theme: {
default: 'dark',
toggleIcon: '/assets/images/theme-button.svg',
toggleIcon: '/_flowershow/theme-button.svg',
},
navLinks: [
{ href: '/about', name: 'About' },
],
};

const siteConfig = { ...defaultConfig, ...userConfig };
const siteConfig = {
...defaultConfig,
...userConfig,
// prevent theme object overrides for
// values not provided in userConfig
theme: {
...defaultConfig.theme,
...userConfig.theme,
}
};

module.exports = siteConfig;
2 changes: 1 addition & 1 deletion templates/default/contentlayer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const sharedFields = {
};

const computedFields = {
url: {
url_path: {
type: 'string',
resolve: (post) => post._raw.flattenedPath,
},
Expand Down
1 change: 0 additions & 1 deletion templates/default/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions templates/default/pages/[[...slug]].js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export default function Page({ body, ...rest }) {
export async function getStaticProps({ params }) {
// params.slug is undefined for root index page
const urlPath = params.slug ? params.slug.join('/') : '';
const page = allDocuments.find((p) => p.url === urlPath);
const page = allDocuments.find((p) => p.url_path === urlPath);
return { props: page };
}

export async function getStaticPaths() {
const paths = allDocuments.map((page) => {
const parts = page.url.split('/');
const parts = page.url_path.split('/');
return { params: { slug: parts } };
});

Expand Down
6 changes: 5 additions & 1 deletion templates/default/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ function MyApp({ Component, pageProps }) {
// end Google Analytics

return (
<ThemeProvider disableTransitionOnChange attribute="class" defaultTheme={siteConfig.theme.default}>
<ThemeProvider
disableTransitionOnChange attribute="class"
defaultTheme={siteConfig.theme.default}
forcedTheme={siteConfig.theme.default ? null : 'light'}
>
<DefaultSeo defaultTitle={siteConfig.title} {...siteConfig.nextSeo} />
{/* Global Site Tag (gtag.js) - Google Analytics */}
{siteConfig.analytics
Expand Down