Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8. Chore pages top level single pages #12

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
108 changes: 95 additions & 13 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
const { DateTime } = require('luxon');
const {DateTime} = require('luxon');
const fs = require('fs');
const pluginRss = require('@11ty/eleventy-plugin-rss');
const pluginNavigation = require('@11ty/eleventy-navigation');
const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');
const {markdownItTable} = require('markdown-it-table');
const yaml = require("js-yaml");
const svgSprite = require("eleventy-plugin-svg-sprite");
const { imageShortcode, imageWithClassShortcode } = require('./config');
const {imageShortcode, imageWithClassShortcode} = require('./config');
const pluginTOC = require('eleventy-plugin-toc')
const pluginMermaid = require("@kevingimbel/eleventy-plugin-mermaid");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const inspect = require("util").inspect;
const striptags = require("striptags");

module.exports = function (config) {
// Set pathPrefix for site
let pathPrefix = '/';

// Copy the `admin` folders to the output
config.addPassthroughCopy('admin');

// Copy USWDS init JS so we can load it in HEAD to prevent banner flashing
config.addPassthroughCopy({'./node_modules/@uswds/uswds/dist/js/uswds-init.js': 'assets/js/uswds-init.js'});
config.addPassthroughCopy({
'admin': 'admin',
'_assets': 'assets',
'_img': 'img',
'resources': 'resources',
'favicon.ico': 'favicon.ico',
'./node_modules/PrismJS/themes/prism-coldark-dark.css': 'assets/styles/prism-atom-dark.css',
'./node_modules/@uswds/uswds/dist/js/uswds-init.js': 'assets/js/uswds-init.js',
'./node_modules/anchor-js/anchor.min.js': 'assets/js/anchor.min.js'
});

config.addFilter("striptags", (content) => {
return striptags(content);
});

// Add plugins
// Add plugins.html
config.addPlugin(pluginRss);
config.addPlugin(pluginNavigation);

Expand All @@ -36,18 +52,24 @@ module.exports = function (config) {
svgShortcode: 'usa_icons'
});

config.addPlugin(pluginTOC, {
tags: ['h2']
});

// Allow yaml to be used in the _data dir
config.addDataExtension("yaml", contents => yaml.load(contents));

config.addFilter("debug", (content) => `<pre>${inspect(content)}</pre>`)

config.addFilter('readableDate', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat(
'dd LLL yyyy'
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat(
'LLLL d, yyyy'
);
});

// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
config.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd');
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd');
});

// Get the first `n` elements of a collection.
Expand Down Expand Up @@ -85,20 +107,64 @@ module.exports = function (config) {
return filterTagList([...tagSet]);
});

config.addPlugin(syntaxHighlight, {
highlight: function (str, lang) {
if (lang === "mermaid") {
// Bypass syntax highlighting for mermaid code blocks
return `<pre class="mermaid cg-diagrams">${str}</pre>`;
}

// Use the default syntax highlighting for other languages
const hljs = require("highlight.js");
if (hljs.getLanguage(lang)) {
return `<pre><code class="language-${lang}">${hljs.highlight(str, {language: lang}).value}</code></pre>`;
}

// Fallback: Return the code without highlighting if no valid language
return `<pre><code>${str}</code></pre>`;
}
});
config.addPlugin(pluginMermaid, {
html_tag: 'div',
extra_classes: 'cg-diagrams',
mermaid_config: {
theme: 'base'
}
});

function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

// Customize Markdown library and settings:
let markdownLibrary = markdownIt({
html: true,
breaks: true,
linkify: true,
linkify: false
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
placement: 'after',
class: 'direct-link',
symbol: '#',
symbol: '',
level: [1, 2, 3, 4],
}),
slugify: config.getFilter('slug'),
}).use(markdownItTable);
config.addFilter("markdown", (content) => {
return markdownLibrary.render(content);
});
markdownLibrary.renderer.rules.link_open = function (tokens, idx, options, env, self) {
const href = tokens[idx].attrGet("href");
if (href && href.startsWith("http")) {
tokens[idx].attrPush(["target", "_blank"]);
tokens[idx].attrPush(["rel", "noopener noreferrer"]);
}
return self.renderToken(tokens, idx, options);
};
markdownLibrary.renderer.rules.code_inline = (tokens, idx, {langPrefix = ''}) => {
const token = tokens[idx];
return `<code class="${langPrefix}plaintext">${htmlEntities(token.content)}</code>&nbsp;`;
};
config.setLibrary('md', markdownLibrary);

// Override Browsersync defaults (used only with --serve)
Expand All @@ -109,7 +175,7 @@ module.exports = function (config) {

browserSync.addMiddleware('*', (req, res) => {
// Provides the 404 content without redirect.
res.writeHead(404, { 'Content-Type': 'text/html; charset=UTF-8' });
res.writeHead(404, {'Content-Type': 'text/html; charset=UTF-8'});
res.write(content_404);
res.end();
});
Expand All @@ -134,6 +200,22 @@ module.exports = function (config) {
pathPrefix = process.env.BASEURL
}

config.addUrlTransform((page) => {
if (page.url.startsWith("/content/knowledge-base/articles")) {
return page.url.replace("/pages/knowledge-base/articles", "/knowledge-base");
}
if (page.url.startsWith("/content/pages/knowledge-base/articles")) {
return page.url.replace("/content/pages/knowledge-base/articles", "/content/knowledge-base");
}
if (page.url.startsWith("/content/news/articles/")) {
let dateMatches = page.url.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}/g);
let date = !!dateMatches && dateMatches.length > 0 ? dateMatches[0].replaceAll('-', '/') : '';
let descriptionMatches = page.url.match(/[A-Za-z]+-[A-Za-z]+/);
let description = !!descriptionMatches && descriptionMatches.length > 0 ? descriptionMatches[descriptionMatches.length - 1] + '/' : '';
return `/${date}/${description}`;
}
});

return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
Expand Down
Binary file not shown.
Binary file added _assets/documents/AFWERX-case-study.pdf
Binary file not shown.
Binary file not shown.
Binary file added _assets/documents/Federalist-One-Pager.pdf
Binary file not shown.
Binary file not shown.
Binary file added _assets/documents/Pages-Proposal.pdf
Binary file not shown.
Binary file added _assets/documents/afwerx-success.pdf
Binary file not shown.
Binary file not shown.
Binary file added _assets/documents/coe-success.pdf
Binary file not shown.
Binary file added _assets/documents/doi-success.pdf
Binary file not shown.
Binary file added _assets/documents/example-diagram-1.pdf
Binary file not shown.
Binary file added _assets/documents/example-diagram-2.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added _assets/documents/how-pages-works-diagram.pdf
Binary file not shown.
Binary file added _assets/documents/pages-compliance-memo.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions _data/assetPaths.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"admin.js": "/assets/js/admin-OYJBR6FH.js",
"admin.map": "/assets/js/admin-OYJBR6FH.js.map",
"app.js": "/assets/js/app-ZQYILJ3O.js",
"app.map": "/assets/js/app-ZQYILJ3O.js.map",
"styles.css": "/assets/styles/styles-2OYWFHCJ.css",
"styles.map": "/assets/styles/styles-2OYWFHCJ.css.map"
"app.js": "/assets/js/app-L3434OIE.js",
"app.map": "/assets/js/app-L3434OIE.js.map",
"styles.css": "/assets/styles/styles-QGJC3V2K.css",
"styles.map": "/assets/styles/styles-QGJC3V2K.css.map"
}
45 changes: 41 additions & 4 deletions _data/collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,53 @@
# This is simple, hopefully provides you with a good enough example to make changes as needed
- name: GSA
url: https://gsa.gov
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.

- name: USDA
url: http://usda.gov/
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.

- name: Performance.gov
url: http://performance.gov/
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.

- name: Login.gov
url: https://login.gov
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.



- label: cloud.gov knowledge base
name: kbarticles
folder: content/knowledge-base/articles/
create: true
slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
editor:
preview: false
fields:
- { label: 'Layout', name: 'layout', widget: 'hidden', default: 'layouts/post' }
- { label: 'Tags', name: 'tags', widget: 'hidden', default: [ 'posts' ] }
- { label: "Title", name: "title", widget: "string" }
- { label: "Author", name: "author", widget: "string" }
- {
label: "Publish Date",
name: "date",
widget: "datetime",
format: 'YYYY-MM-DD',
dateFormat: 'YYYY-MM-DD',
timeFormat: false
}
- {
label: "Image",
name: "image",
widget: "image",
allow_multiple: false,
required: false
}
- {
label: "Image Alt Text",
name: "image_alt_text",
widget: "string",
required: false
}
- { label: "Body", name: "body", widget: "markdown" }
125 changes: 125 additions & 0 deletions _data/pages/navigation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
primary:
- name: Features
url: /pages/features/
- name: Success Stories
url: /pages/success-stories/
- name: Documentation
url: /pages/documentation/
- name: Pricing
url: /pages/pricing/
- name: Knowledge Base
url: /pages/knowledge-base/
- name: Contact
url: /pages/contact/
# Look inside assets/js/index.js to see that how this url changes depending on enviroment
secondary:
- name: Platform Status
url: https://cloudgov.statuspage.io/
- name: Login
url: https://pages.cloud.gov
external: true
class: usa-button usa-button-secondary nav-button

footer:
- text: Home
href: /pages/
- text: Features
href: /pages/features/
- text: Success Stories
href: /pages/success-stories/
- text: Documentation
href: /pages/documentation/
- text: Pricing
href: /pages/pricing/
- text: Knowledge Base
href: /pages/knowledge-base/
- text: Contact
href: /pages/contact/
- text: Manage Sites
href: https://pages.cloud.gov
external: true

sidenav:
- text: Using Pages
href: /pages/documentation/
subfolderitems:
- text: Why use Pages?
href: /pages/documentation/why-use-pages/
- text: Access and permissions
href: /pages/documentation/access-permissions/
- text: Adding a user to an Organization
href: /pages/documentation/adding-users/
- text: Before you launch
href: /pages/documentation/before-you-launch/
- text: Getting started with a sandbox
href: /pages/documentation/sandbox/
- text: "21st Century IDEA"
href: /pages/documentation/21st-century-idea/
- text: Getting started with Decap CMS
href: /pages/documentation/getting-started-with-decap-cms/
- text: Included with Pages
href: /pages/documentation/included-with-pages/
- text: Instructional demos
href: /pages/documentation/instructional-demos/
- text: Builds and previews
href: /pages/documentation/previews/
- text: Custom domains
href: /pages/documentation/custom-domains/
- text: Migration guide
href: /pages/documentation/migration-guide/
- text: Adding forms
href: /pages/documentation/forms/
- text: Adding search
href: /pages/documentation/search/
- text: Site templates
href: /pages/documentation/templates/
- text: Customizing your site
href: /pages/documentation/customization/
- text: Using the markup languages
href: /pages/documentation/resources/
- text: Content guide
href: /pages/documentation/content-guide/
- text: Custom headers
href: /pages/documentation/custom-headers/
- text: Federalist.json
href: /pages/documentation/federalist-json/
- text: For security and compliance
href: /pages/documentation/
subfolderitems:
- text: Security and Compliance
href: /pages/documentation/security-and-compliance
- text: Customer responsibilities
href: /pages/documentation/customer-responsibilities/
- text: FedRAMP Tracker
href: /docs/overview/fedramp-tracker/
- text: Automated Site Reports
href: /pages/documentation/automated-site-reports/
- text: For developers
href: /pages/documentation/
subfolderitems:
- text: How builds work
href: /pages/documentation/how-builds-work/
- text: Specific build errors
href: /pages/documentation/build-errors/
- text: Environment variables on builds
href: /pages/documentation/env-vars-on-content-builds/
- text: Pages and cloud.gov
href: /pages/documentation/cloud-gov/
- text: Node on Pages
href: /pages/documentation/node-on-pages/
- text: RVM on Pages
href: /pages/documentation/rvm-on-pages/
- text: Bundler on Pages
href: /pages/documentation/bundler-on-pages/
- text: Caching Build Dependencies
href: /pages/documentation/cache-dependencies/
- text: Supported site engines
href: /pages/documentation/supported-site-engines/
- text: Large file handling
href: /pages/documentation/large-file-handling/
- text: Renaming your site's repository
href: /pages/documentation/renaming-site-repository/
- text: Monorepos on Pages
href: /pages/documentation/monorepos-on-pages/
- text: External tools and resources
href: /pages/documentation/external-tools-and-resources/
14 changes: 14 additions & 0 deletions _data/pages/templates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

items:
- title: Eleventy (11ty) - U.S. Web Design System v3.0
docs_url: https://github.com/cloud-gov/pages-uswds-11ty
preview_url: https://uswds-11ty.pages.cloud.gov/
img: https://pages.cloud.gov/images/pages-uswds-v3-11ty-thumbnail.png
order: 2
summary: ""
- title: Gatsby - U.S. Web Design System v2.0
docs_url: https://github.com/cloud-gov/pages-uswds-gatsby
preview_url: https://uswds-gatsby.pages.cloud.gov/
img: https://pages.cloud.gov/images/pages-uswds-v2-gatsby-thumbnail.png
order: 3
summary: ""
Loading
Loading