diff --git a/greenwood.config.js b/greenwood.config.js index f0760558..00a865c7 100644 --- a/greenwood.config.js +++ b/greenwood.config.js @@ -1,5 +1,39 @@ import { greenwoodPluginCssModules } from "@greenwood/plugin-css-modules"; import { greenwoodPluginImportRaw } from "@greenwood/plugin-import-raw"; +import { ResourceInterface } from "@greenwood/cli/src/lib/resource-interface.js"; + +// TODO would be nice to find a better way to solve this problem +// https://github.com/ProjectEvergreen/www.greenwoodjs.dev/issues/125 +class ActiveFrontmatterDocsTitleRestorerResource extends ResourceInterface { + constructor() { + super(); + this.extensions = ["html"]; + this.contentType = "text/html"; + this.matches = ["My Blog - Active Frontmatter", "My Site - Going Further"]; + this.replacer = "${globalThis.page.title}"; + } + + async shouldIntercept(url, request, response) { + return response.headers.get("Content-Type")?.indexOf(this.contentType) >= 0; + } + + async intercept(url, request, response) { + let body = await response.text(); + + this.matches.forEach((match) => { + if (body.indexOf(match) > 0) { + const titleParts = match.split("-"); + + body = body.replace( + new RegExp(String.raw`${match}`, "g"), + `${titleParts[0]}- ${this.replacer}`, + ); + } + }); + + return new Response(body); + } +} export default { activeContent: true, @@ -10,7 +44,15 @@ export default { plugins: ["@mapbox/rehype-prism", "rehype-slug", "rehype-autolink-headings", "remark-github"], }, - plugins: [greenwoodPluginCssModules(), greenwoodPluginImportRaw()], + plugins: [ + greenwoodPluginCssModules(), + greenwoodPluginImportRaw(), + { + name: "active-frontmatter-docs-title-restorer-resource", + type: "resource", + provider: (compilation) => new ActiveFrontmatterDocsTitleRestorerResource(compilation), + }, + ], polyfills: { importAttributes: ["css", "json"], diff --git a/src/assets/docs/graphql-playground.png b/src/assets/docs/graphql-playground.png new file mode 100644 index 00000000..825e9ab9 Binary files /dev/null and b/src/assets/docs/graphql-playground.png differ diff --git a/src/components/heading-box/heading-box.module.css b/src/components/heading-box/heading-box.module.css index 613b975f..ef296b77 100644 --- a/src/components/heading-box/heading-box.module.css +++ b/src/components/heading-box/heading-box.module.css @@ -17,4 +17,8 @@ .slotted { margin: var(--size-4) 0 var(--size-1); + + & a { + color: var(--color-accent); + } } diff --git a/src/components/side-nav/side-nav.js b/src/components/side-nav/side-nav.js index adc08b82..1c002e22 100644 --- a/src/components/side-nav/side-nav.js +++ b/src/components/side-nav/side-nav.js @@ -29,6 +29,10 @@ export default class SideNav extends HTMLElement { } }); + if (sections.length === 0) { + return; + } + this.innerHTML = `
Having to repeat things when programming is no fun, and that's why (web) component based development is so useful! As websites start to grow, there comes a point where being able to have access to the content and structure of your site's layout programmatically becomes incredibly useful for generating repetitive HTML.
+Welcome to our docs, we're excited to help you get the most out of Greenwood and the web!
+