diff --git a/.github/workflows/ssr_tests.js.yml b/.github/workflows/ssr_tests.js.yml index 1b188eaa2..a5944d604 100644 --- a/.github/workflows/ssr_tests.js.yml +++ b/.github/workflows/ssr_tests.js.yml @@ -1,11 +1,12 @@ -# # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions +# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions name: SSR Tests on: - push: - branches: [next] + # push: + # branches: [next] + workflow_dispatch: jobs: ssr_test: diff --git a/docs/.eleventy.js b/docs/.eleventy.js index c32049193..fb0dbfd58 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -1,3 +1,4 @@ +import * as path from 'node:path'; import { anchorHeadingsPlugin } from './_utils/anchor-headings.js'; import { codeExamplesPlugin } from './_utils/code-examples.js'; import { copyCodePlugin } from './_utils/copy-code.js'; @@ -6,9 +7,10 @@ import { highlightCodePlugin } from './_utils/highlight-code.js'; import { markdown } from './_utils/markdown.js'; import { removeDataAlphaElements } from './_utils/remove-data-alpha-elements.js'; // import { formatCodePlugin } from './_utils/format-code.js'; -import litPlugin from '@lit-labs/eleventy-plugin-lit'; +// import litPlugin from '@lit-labs/eleventy-plugin-lit'; import { readFile } from 'fs/promises'; -import componentList from './_data/componentList.js'; +import nunjucks from 'nunjucks'; +// import componentList from './_data/componentList.js'; import * as filters from './_utils/filters.js'; import { outlinePlugin } from './_utils/outline.js'; import { replaceTextPlugin } from './_utils/replace-text.js'; @@ -16,7 +18,10 @@ import { searchPlugin } from './_utils/search.js'; import process from 'process'; -const packageData = JSON.parse(await readFile('./package.json', 'utf-8')); +import * as url from 'url'; +const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); + +const packageData = JSON.parse(await readFile(path.join(__dirname, '..', 'package.json'), 'utf-8')); const isAlpha = process.argv.includes('--alpha'); const isDev = process.argv.includes('--develop'); @@ -24,12 +29,22 @@ const globalData = { package: packageData, isAlpha, layout: 'page.njk', + server: { + head: '', + loginOrAvatar: '', + flashes: '', + }, }; const passThroughExtensions = ['js', 'css', 'png', 'svg', 'jpg', 'mp4']; const passThrough = [...passThroughExtensions.map(ext => 'docs/**/*.' + ext)]; export default function (eleventyConfig) { + /** + * This is the guard we use for now to make sure our final built files dont need a 2nd pass by the server. This keeps us able to still deploy the bare HTML files on Vercel until the app is ready. + */ + const serverBuild = process.env.WEBAWESOME_SERVER === 'true'; + // NOTE - alpha setting removes certain pages if (isAlpha) { eleventyConfig.ignores.add('**/experimental/**'); @@ -55,7 +70,38 @@ export default function (eleventyConfig) { // Shortcodes - {% shortCode arg1, arg2 %} eleventyConfig.addShortcode('cdnUrl', location => { - return `https://early.webawesome.com/webawesome@${packageData.version}/dist/` + location.replace(/^\//, ''); + return `https://early.webawesome.com/webawesome@${packageData.version}/dist/` + (location || '').replace(/^\//, ''); + }); + + // Turns `{% server "foo" %} into `{{ server.foo | safe }}` when the WEBAWESOME_SERVER variable is set to "true" + eleventyConfig.addShortcode('server', function (property) { + if (serverBuild) { + return `{{ server.${property} | safe }}`; + } + + return ''; + }); + + eleventyConfig.addTransform('second-nunjucks-transform', function NunjucksTransform(content) { + // For a server build, we expect a server to run the second transform. + if (serverBuild) { + return content; + } + + // Only run the transform on files nunjucks would transform. + if (!this.page.inputPath.match(/.(md|html|njk)$/)) { + return content; + } + + /** This largely mimics what an app would do and just stubs out what we don't care about. */ + return nunjucks.renderString(content, { + // Stub the server EJS shortcodes. + server: { + head: '', + loginOrAvatar: '', + flashes: '', + }, + }); }); // Paired shortcodes - {% shortCode %}content{% endShortCode %} @@ -117,29 +163,6 @@ export default function (eleventyConfig) { ]), ); - // SSR plugin - if (!isDev) { - // - // Problematic components in SSR land: - // - animation (breaks on navigation + ssr with Turbo) - // - mutation-observer (why SSR this?) - // - resize-observer (why SSR this?) - // - tooltip (why SSR this?) - // - const omittedModules = []; - const componentModules = componentList - .filter(component => !omittedModules.includes(component.tagName.split(/wa-/)[1])) - .map(component => { - const name = component.tagName.split(/wa-/)[1]; - return `./dist/components/${name}/${name}.js`; - }); - - eleventyConfig.addPlugin(litPlugin, { - mode: 'worker', - componentModules, - }); - } - // Build the search index eleventyConfig.addPlugin( searchPlugin({ @@ -166,6 +189,31 @@ export default function (eleventyConfig) { eleventyConfig.addPassthroughCopy(glob); } + // // SSR plugin + // // Make sure this is the last thing, we don't want to run the risk of accidentally transforming shadow roots with the nunjucks 2nd transform. + // if (!isDev) { + // // + // // Problematic components in SSR land: + // // - animation (breaks on navigation + ssr with Turbo) + // // - mutation-observer (why SSR this?) + // // - resize-observer (why SSR this?) + // // - tooltip (why SSR this?) + // // + // const omittedModules = []; + // const componentModules = componentList + // .filter(component => !omittedModules.includes(component.tagName.split(/wa-/)[1])) + // .map(component => { + // const name = component.tagName.split(/wa-/)[1]; + // const componentDirectory = process.env.UNBUNDLED_DIST_DIRECTORY || path.join('.', 'dist'); + // return path.join(componentDirectory, 'components', name, `${name}.js`); + // }); + // + // eleventyConfig.addPlugin(litPlugin, { + // mode: 'worker', + // componentModules, + // }); + // } + return { markdownTemplateEngine: 'njk', dir: { diff --git a/docs/_includes/base.njk b/docs/_includes/base.njk index 0a01532bf..21bfd33a6 100644 --- a/docs/_includes/base.njk +++ b/docs/_includes/base.njk @@ -1,5 +1,5 @@ - + {% include 'head.njk' %} @@ -50,6 +50,9 @@ Search / + + {# Login #} + {% server "loginOrAvatar" %} @@ -76,14 +79,19 @@ {% endif %} + {# Main #}
{# Expandable outline #} + {% if hasOutline %} + {% endif %} + +
{% server "flashes" %}
{% block header %} {% include 'breadcrumbs.njk' %} diff --git a/docs/_includes/breadcrumbs.njk b/docs/_includes/breadcrumbs.njk index 5f9fa145b..96d5563e8 100644 --- a/docs/_includes/breadcrumbs.njk +++ b/docs/_includes/breadcrumbs.njk @@ -1,8 +1,11 @@ -{% set breadcrumbs = page.url | breadcrumbs %} -{% if breadcrumbs.length > 0 %} +{% set ancestors = page.url | ancestors %} + +{% if ancestors.length > 0 %} - {% for crumb in breadcrumbs %} - {{ crumb.title }} + {% for ancestor in ancestors %} + {% if ancestor.page.url != "/" %} + {{ ancestor.data.title }} + {% endif %} {% endfor %} {# Current page #} diff --git a/docs/_includes/grouped-pages.njk b/docs/_includes/grouped-pages.njk index 84cf846f5..2273f4c98 100644 --- a/docs/_includes/grouped-pages.njk +++ b/docs/_includes/grouped-pages.njk @@ -1,12 +1,18 @@ {# Cards for pages listed by category #}
-{% for category, pages in allPages | groupByTags(categories) -%} -

{{ category | getCategoryTitle(categories) }}

- {%- for page in pages -%} - {%- if not page.data.parent or listChildren -%} - {% include "page-card.njk" %} - {%- endif -%} - {%- endfor -%} +{% set groupedPages = allPages | groupPages(categories, page) %} +{% for category, pages in groupedPages -%} + {% if groupedPages.meta.groupCount > 1 and pages.length > 0 %} +

+ {% if pages.meta.url %}{{ pages.meta.title }} + {% else %} + {{ pages.meta.title }} + {% endif %} +

+ {% endif %} + {%- for page in pages -%} + {% include "page-card.njk" %} + {%- endfor -%} {%- endfor -%}
diff --git a/docs/_includes/head.njk b/docs/_includes/head.njk index 695aa836b..c6bd79be7 100644 --- a/docs/_includes/head.njk +++ b/docs/_includes/head.njk @@ -23,10 +23,12 @@ - + +{# Internal components #} + {# Web Awesome #} - + {# Preset Theme #} @@ -47,3 +49,6 @@ + +{# Used by Web Awesome App to inject other assets into the head. #} +{% server "head" %} diff --git a/docs/_includes/page-card.njk b/docs/_includes/page-card.njk index f63d813ed..b684a3487 100644 --- a/docs/_includes/page-card.njk +++ b/docs/_includes/page-card.njk @@ -2,7 +2,7 @@
- {% include "svgs/" + (page.data.icon or "thumbnail-placeholder") + ".njk" %} + {% include "svgs/" + (page.data.icon or "thumbnail-placeholder") + ".njk" ignore missing %}
{{ page.data.title }} {% if pageSubtitle -%} diff --git a/docs/_includes/sidebar-group.njk b/docs/_includes/sidebar-group.njk index c49ef48da..b723d22ab 100644 --- a/docs/_includes/sidebar-group.njk +++ b/docs/_includes/sidebar-group.njk @@ -1,9 +1,12 @@ {# Some collections (like "patterns") will not have any items in the alpha build for example. So this checks to make sure the collection exists. #} {% if collections[tag] -%} {% set groupUrl %}/docs/{{ tag }}/{% endset %} + {% set groupItem = groupUrl | getCollectionItemFromUrl %} + {% set children = groupItem.data.children if groupItem.data.children.length > 0 else (collections[tag] | sort) %} +

- {% if groupUrl | getCollectionItemFromUrl %} + {% if groupItem %} {{ title or (tag | capitalize) }} @@ -12,10 +15,8 @@ {% endif %}

diff --git a/docs/_includes/sidebar-link.njk b/docs/_includes/sidebar-link.njk index dab3e32a0..d44628b07 100644 --- a/docs/_includes/sidebar-link.njk +++ b/docs/_includes/sidebar-link.njk @@ -1,4 +1,4 @@ -{% if not (isAlpha and page.data.noAlpha) and page.fileSlug != tag and not page.data.unlisted -%} +{% if page | show -%}
  • {{ page.data.title }} {% if page.data.status == 'experimental' %}{% endif %} diff --git a/docs/_includes/svgs/theme-color.njk b/docs/_includes/svgs/theme-color.njk index 0c41f7f5d..a5d543ced 100644 --- a/docs/_includes/svgs/theme-color.njk +++ b/docs/_includes/svgs/theme-color.njk @@ -1,13 +1,13 @@ {% set themeId = theme.fileSlug %} -
    -