Skip to content

Commit 1ba834e

Browse files
Add base template for 11ty and catalog pages (#1365)
1 parent c63cb32 commit 1ba834e

File tree

5 files changed

+82
-21
lines changed

5 files changed

+82
-21
lines changed

packages/site-content/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"command": "eleventy --config=eleventy.config.prod.cjs",
1616
"files": [
1717
"eleventy.config.prod.cjs",
18-
"site"
18+
"site",
19+
"../site-server/lib/templates/**/*.js"
1920
],
2021
"output": [
2122
"_site"
@@ -29,14 +30,16 @@
2930
"files": [
3031
"eleventy.config.dev.cjs",
3132
"site",
32-
"!site/assets"
33+
"!site/assets",
34+
"../site-server/lib/templates/**/*.js"
3335
],
3436
"output": [
3537
"_dev"
3638
]
3739
}
3840
},
3941
"dependencies": {
40-
"@11ty/eleventy": "^1.0.2"
42+
"@11ty/eleventy": "^1.0.2",
43+
"@webcomponents/internal-site-server": "^0.0.0"
4144
}
4245
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
module.exports = {
8+
async render(data) {
9+
const {renderPage} = await import(
10+
'@webcomponents/internal-site-server/lib/templates/base.js'
11+
);
12+
return renderPage(data);
13+
},
14+
};

packages/site-content/site/index.html

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
<!DOCTYPE html>
2-
<html lang="en">
3-
<head>
4-
<meta charset="utf-8" />
5-
<title>webcomponents.org</title>
6-
<style>
7-
body {
8-
margin: 0;
9-
}
10-
</style>
11-
</head>
12-
<body>
13-
<wco-top-bar></wco-top-bar>
14-
<h2>🚧 Under construction! 🚧</h2>
15-
<script type="module" src="./js/homepage.js"></script>
16-
</body>
17-
</html>
1+
---
2+
layout: "layouts/base.11ty.cjs"
3+
title: "Web Components"
4+
scripts:
5+
- "./js/homepage.js"
6+
---
7+
<wco-top-bar></wco-top-bar>
8+
<h2>🚧 Under construction! 🚧</h2>

packages/site-server/src/catalog/router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import Router from '@koa/router';
88
import {ApolloClient, InMemoryCache, gql} from '@apollo/client/core/index.js';
9+
import {renderPage} from '../templates/base.js';
910
import {renderElement} from './element-template.js';
1011

1112
const CATALOG_GRAPHQL_URL =
@@ -85,7 +86,7 @@ catalogRouter.get('/element/:path+', async (context) => {
8586
manifest: customElementsManifest,
8687
});
8788

88-
context.body = content;
89+
context.body = renderPage({title: `${packageName}/${elementName}`, content});
8990
context.type = 'html';
9091
context.status = 200;
9192
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
import {escapeHTML} from '../catalog/escape-html.js';
7+
8+
export const renderPage = (data: {
9+
scripts?: Array<string>;
10+
title?: string;
11+
content?: string;
12+
}) => {
13+
return `<!doctype html>
14+
<html lang="en">
15+
<head>
16+
<meta charset="utf-8">
17+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
18+
<link
19+
href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;700&display=swap"
20+
rel="stylesheet"
21+
/>
22+
<link
23+
href="https://fonts.googleapis.com/css?family=Material+Icons&display=block"
24+
rel="stylesheet"
25+
/>
26+
${(data.scripts ?? [])
27+
.map((s) => `<script type="module" src="${s}"></script>`)
28+
.join('\n')}
29+
<style>
30+
body {
31+
margin: 0;
32+
--mdc-typography-font-family: 'Open Sans', Arial, Helvetica, sans-serif;
33+
font-family: var(--mdc-typography-font-family);
34+
font-size: 14px;
35+
line-height: 1.5;
36+
min-height: 100vh;
37+
}
38+
@media (max-width: 500px), (max-height: 500px) {
39+
body {
40+
max-height: 100vh;
41+
overflow: auto;
42+
}
43+
}
44+
</style>
45+
<title>${escapeHTML(data.title)}</title>
46+
</head>
47+
<body>
48+
${data.content}
49+
</body>
50+
</html>
51+
`;
52+
};

0 commit comments

Comments
 (0)