From 79bafc513ad07dccc6134794198518b30d8f9051 Mon Sep 17 00:00:00 2001 From: Konnor Rogers Date: Tue, 18 Mar 2025 13:04:24 -0400 Subject: [PATCH 1/7] 11ty for webawesome-app (#803) * working on integration * 11ty for webawesome + app * add flashes * additional changes * prettier * add note about nunjucks * prettier --- docs/.eleventy.js | 22 +++++++++++++++++++--- docs/_includes/base.njk | 8 ++++++++ docs/_includes/head.njk | 4 ++++ docs/_layouts/page.njk | 9 +++++++-- docs/index.md | 4 +--- scripts/build.js | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 8 deletions(-) diff --git a/docs/.eleventy.js b/docs/.eleventy.js index c32049193..29d755be3 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'; @@ -16,7 +17,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,6 +28,12 @@ const globalData = { package: packageData, isAlpha, layout: 'page.njk', + + server: { + head: '', + loginOrAvatar: '', + flashes: '', + }, }; const passThroughExtensions = ['js', 'css', 'png', 'svg', 'jpg', 'mp4']; @@ -55,7 +65,12 @@ 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_variable "foo" %} into `{{ server.foo | safe }}` + eleventyConfig.addShortcode('server', function (property) { + return `{{ server.${property} | safe }}`; }); // Paired shortcodes - {% shortCode %}content{% endShortCode %} @@ -131,7 +146,8 @@ export default function (eleventyConfig) { .filter(component => !omittedModules.includes(component.tagName.split(/wa-/)[1])) .map(component => { const name = component.tagName.split(/wa-/)[1]; - return `./dist/components/${name}/${name}.js`; + const componentDirectory = process.env.UNBUNDLED_DIST_DIRECTORY || path.join('.', 'dist'); + return path.join(componentDirectory, 'components', name, `${name}.js`); }); eleventyConfig.addPlugin(litPlugin, { diff --git a/docs/_includes/base.njk b/docs/_includes/base.njk index 0a01532bf..6cbfea2de 100644 --- a/docs/_includes/base.njk +++ b/docs/_includes/base.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/head.njk b/docs/_includes/head.njk index 695aa836b..89a303d24 100644 --- a/docs/_includes/head.njk +++ b/docs/_includes/head.njk @@ -47,3 +47,7 @@ + + +{# Used by Web Awesome App to inject other assets into the head. #} +{% server "head" %} diff --git a/docs/_layouts/page.njk b/docs/_layouts/page.njk index a55a02c21..203527a44 100644 --- a/docs/_layouts/page.njk +++ b/docs/_layouts/page.njk @@ -1,4 +1,9 @@ -{% set hasSidebar = true %} -{% set hasOutline = false %} +{% if hasSidebar == undefined %} + {% set hasSidebar = true %} +{% endif %} + +{% if hasOutline == undefined %} + {% set hasOutline = false %} +{% endif %} {% extends "../_includes/base.njk" %} diff --git a/docs/index.md b/docs/index.md index aa3d060f5..9ae2e8a82 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,8 +4,6 @@ description: Build better with Web Awesome, the open source library of web compo layout: page --- - -