Skip to content

Commit

Permalink
Add option to set additional meta tags
Browse files Browse the repository at this point in the history
  • Loading branch information
moonglum committed Sep 19, 2024
1 parent 73ac8c5 commit 3c5cc73
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ unreleased

significant changes for end users:

* allow to set additional meta tags via the `meta` configuration:
* expects an object, with the keys being the `name` and the values being the `content`
* we no longer bundle the --serve and --live-serve dependencies - you will be asked to install them
* reduce faucet dependencies
* update all dependencies
Expand Down
3 changes: 3 additions & 0 deletions example/aiur.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

exports.title = "Example Styleguide";
exports.language = "en";
exports.meta = {
robots: "noindex"
};

exports.vendor = {
styles: [{
Expand Down
1 change: 1 addition & 0 deletions lib/generate_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = async (navigation, manifest) => {
<title>${page.title || ""}</title>
<meta name="description" content="${page.description || ""}">
<meta name="viewport" content="width=device-width,initial-scale=1">
${page.meta}
<link href="${manifest.get("style-aiur.css")}" rel="stylesheet">
</head>
<body id="aiur">
Expand Down
9 changes: 7 additions & 2 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ let { repr } = require("faucet-pipeline-core/lib/util");
let colonParse = require("metacolon");

module.exports = class Page {
constructor(slug, sourcePath, children, { language, title, description }, dataPath) {
constructor(slug, sourcePath, children, { language, title, description, meta }, dataPath) {
this.slug = slug || "";
this.sourcePath = sourcePath;
this.children = children || null;
this.config = { language, title, description };
this.config = { language, title, description, meta };
this.dataPath = dataPath;
}

Expand All @@ -27,13 +27,18 @@ module.exports = class Page {
this.heading = headers.title;
this.title = [headers.title, this.config.title].filter(x => x).join(" | ");
this.description = headers.description || this.config.description;
this.meta = this.buildMeta();
this.status = headers.status;
this.version = headers.version;
this.tags = headers.tags;
this.body = body;
return this;
}

buildMeta() {
return Object.entries(this.config.meta || {}).map(x => `<meta name="${x[0]}" content="${x[1]}">`).join("\n");
}

toString() {
let filepath = repr(this.sourcePath, false);
let suffix = this.body ? " resolved" : "";
Expand Down
1 change: 1 addition & 0 deletions test/expectations/atoms/button/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>Button</title>
<meta name="description" content="interactive widget">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex">
<link href="/style-aiur.css" rel="stylesheet">
</head>
<body id="aiur">
Expand Down
1 change: 1 addition & 0 deletions test/expectations/atoms/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>Atoms</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex">
<link href="/style-aiur.css" rel="stylesheet">
</head>
<body id="aiur">
Expand Down
1 change: 1 addition & 0 deletions test/expectations/atoms/strong/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>strong</title>
<meta name="description" content="pretty strong component">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex">
<link href="/style-aiur.css" rel="stylesheet">
</head>
<body id="aiur">
Expand Down
1 change: 1 addition & 0 deletions test/expectations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>My Style Guide</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex">
<link href="/style-aiur.css" rel="stylesheet">
</head>
<body id="aiur">
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/aiur.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"use strict";

exports.meta = {
robots: "noindex"
};

exports.pages = {
"": "./welcome.md",
atoms: {
Expand Down

0 comments on commit 3c5cc73

Please sign in to comment.