Skip to content

Commit

Permalink
Correct the blog post and blog page templates
Browse files Browse the repository at this point in the history
This commit:

- Fixes the header, so the title appears
- Removes unused parts of templates
- Removes unused filters
- Renames `image_accessibility` to `image_alt` site-wide
- Sets up partials for images
- Adjusts image asset paths
- Incidentally removes a duplicate layout (`primary` and `guides` were the same)
  • Loading branch information
beechnut committed Jun 25, 2024
1 parent 42f4f37 commit 1171559
Show file tree
Hide file tree
Showing 49 changed files with 169 additions and 239 deletions.
11 changes: 4 additions & 7 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const { readableDate
, teamPhoto
, teamLink
, markdownify
, weightedSort
, asRelativeUrl
, matchPosts } = require('./config/filters');
, weightedSort } = require('./config/filters');
const { postsCollection, servicesCollection, tagsCollection } = require('./config/collections');
const { headingLinks } = require('./config/headingLinks');
const { contrastRatio, humanReadableContrastRatio } = require('./config/wcagColorContrast');
Expand Down Expand Up @@ -107,12 +105,11 @@ module.exports = function (config) { /* eslint-disable-line func-names */
config.addFilter('team_photo', teamPhoto);
// Add a link to an 18F team member's author page
config.addFilter('team_link', teamLink);
config.addFilter('weighted_sort', weightedSort);
config.addFilter('relative_url', asRelativeUrl);
config.addFilter('match_posts', matchPosts);
config.addFilter('limit', (arr, limit) => arr.slice(0, limit));
config.addFilter('matching', (collection, author) => collection.filter((post) => post.data.authors.includes(author)));
config.addFilter('markdownify', markdownify);
config.addFilter('relative_url', (url) => url);
config.addFilter('weighted_sort', weightedSort);

// Color contrast checkers for the color matrix in the Brand guide
config.addFilter('contrastRatio', contrastRatio);
Expand Down Expand Up @@ -188,7 +185,7 @@ module.exports = function (config) { /* eslint-disable-line func-names */
// Check for external URLs. External means any site that is not a federal .gov url
// This check can't detect state/local .gov domains. Those will need to be
// manually adjusted
const baseURL = new URL('https://guides.18f.gov/');
const baseURL = new URL('https://18f.gsa.gov/');
const hrefValue = token.attrGet('href');

if (!(new URL(hrefValue, baseURL).hostname.endsWith('.gov'))) {
Expand Down
12 changes: 6 additions & 6 deletions _data/assetPaths.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"admin.js": "/assets/js/admin-3AAZDPS4.js",
"admin.map": "/assets/js/admin-3AAZDPS4.js.map",
"app.js": "/assets/js/app-VJ5WPKYD.js",
"app.map": "/assets/js/app-VJ5WPKYD.js.map",
"styles.css": "/assets/styles/styles-YNYM6ERT.css",
"styles.map": "/assets/styles/styles-YNYM6ERT.css.map"
"admin.js": "/assets/js/admin-TH6ADBUC.js",
"admin.map": "/assets/js/admin-TH6ADBUC.js.map",
"app.js": "/assets/js/app-XKFC5Y7M.js",
"app.map": "/assets/js/app-XKFC5Y7M.js.map",
"styles.css": "/assets/styles/styles-L2BO6PLI.css",
"styles.map": "/assets/styles/styles-L2BO6PLI.css.map"
}
38 changes: 38 additions & 0 deletions _includes/adjacent_page_links.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% assign previous = collections.posts | getPreviousCollectionItem: page %}
{% assign next = collections.posts | getNextCollectionItem: page %}
{% if previous or next %}
<section class="margin-top-6 post-pagination">
<div class="grid-container">
<hr class="hr-1-base-lighter">
<div class="grid-row grid-gap">
<div class="grid-col-6">
{% if previous %}
<a href="{{ previous.url | url }}"
class="text-no-underline post-pagination__link"
>
<h2 class="post-pagination__heading">
{% include "svg/icons/arrow-left.svg" %}
Previous Post
</h2>
<p class="measure-1 text-bold text-primary-darkest">{{ previous.data.title }}</p>
</a>
{% endif %}
</div>
<div class="grid-col-6 text-right">
{% if next %}
<a href="{{ next.url | url }}"
class="text-no-underline post-pagination__link"
>
<h2 class="post-pagination__heading">
Next Post
{% include "svg/icons/arrow-right.svg" %}
</h2>
<p class="measure-1 float-right text-bold text-primary-darkest text-right">{{ next.data.title }}</p>
</a>
{% endif %}
</div>
</div>
<hr class="hr-1-base-lighter">
</div>
</section>
{% endif %}
11 changes: 11 additions & 0 deletions _includes/feature-image-small.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% if image and image_feature_small %}
{% comment %}
The blog posts frontmatter has historically had the image paths set
with an absolute path, by including the leading slash.

The image shortcode needs the image URL without that slash,
hence the assign statement here removing the first one.
{% endcomment %}
{% assign rel_image_path = image | remove_first: "/" %}
{% image_with_class rel_image_path "image-feature-small" image_alt %}
{% endif %}
25 changes: 15 additions & 10 deletions _includes/feature-image.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{% assign include_image = image | default: page.image %}
{% assign include_image_alt = image | default: page.image_alt | default: "" %}
{% assign include_figcaption = image_figcaption | default: page.image_figcaption %}

{% if page.hero %}
<figure class="post-feature_image" role="img" title="{{ include_image_alt }}" style="background-image: url('{{ site.baseurl }}{{ include_image }}')">
{% if include_figcaption %}
<figcaption>{{- include_figcaption -}}</figcaption>
{% endif %}
</figure>
{% if image %}
{% comment %}
I'm wondering if there's a better way to do this, like setting up
a shortcode.
{% endcomment %}
<figure
class="post-feature_image"
role="img"
title="{{ image_alt }}"
style="background-image: url('{{ image | url }}')"
>
{% if image_figcaption %}
<figcaption>{{ image_figcaption }}</figcaption>
{% endif %}
</figure>
{% endif %}
24 changes: 7 additions & 17 deletions _includes/layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,17 @@
{% endif %}
{% endcomment %}
</head>
<body class="{{ layout.class }} {{ page.class }} {% if site.site_width %}site-{{ site.site_width }}{% endif %}">

<body class="{{ layout.class }} {{ page.class }}">
{% include "skipnav.html" %}
{% include "header.html" %}

{% if page.tagline and page.intro %}
<section class="grid-container usa-section">
<div class="grid-row grid-gap">
<div class="tablet:grid-col-4">
<h2 class="font-heading-xl margin-top-0 tablet:margin-bottom-0">{{ page.tagline }}</h2>
</div>
<div class="tablet:grid-col-8 usa-prose">
{{ page.intro | markdownify }}
</div>
</div>
</section>
{% endif %}
{% comment %}
code smell: Altering layouts based on the value of `layout`.

{% if page.layout == 'post' %}
We probably do this because every other layout needs the <main> tag,
while the post layout needs <article> without being wrapped in <main>.
{% endcomment %}
{% if layout == 'post' %}
{{ content }}
{% else %}
<main id="main-content">
Expand All @@ -38,8 +30,6 @@ <h2 class="font-heading-xl margin-top-0 tablet:margin-bottom-0">{{ page.tagline
{% endif %}

{% include "footer.html" %}

{% include "scripts.html" %}

</body>
</html>
26 changes: 0 additions & 26 deletions _includes/layouts/guides.html

This file was deleted.

56 changes: 6 additions & 50 deletions _includes/layouts/post.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
---
layout: default
---
{% comment %}
Some of the `page.` references will need to be deleted — but I'm not yet sure which.
{% endcomment %}

{% if page.image %}
{% comment %}This include will probably need to pass in data explicitly.{% endcomment %}
{% include "feature-image.html" %}
{% endif %}
{% include "feature-image.html" %}

<article id="main-content" class="post-article margin-top-6" itemscope itemtype="http://schema.org/BlogPosting">
<div class="grid-container">
Expand All @@ -30,11 +23,11 @@ <h1 itemprop="name headline">{{ title }}</h1>
<div class="grid-row grid-gap margin-top-8">
<div class="tablet:grid-col-7">
<div class="post-content" itemprop="articleBody">
{% if page.image and page.image_feature_small %}
{% image_with_class page.image "image-feature-small" page.image_accessibility %}
{% endif %}

{% include "feature-image-small.html" %}

{{ content }}

</div>
</div>
<aside class="tablet:grid-offset-1 tablet:grid-col-4">
Expand All @@ -44,49 +37,12 @@ <h1 itemprop="name headline">{{ title }}</h1>
</div>
</article>

{% assign previous = collections.posts | getPreviousCollectionItem: page %}
{% assign next = collections.posts | getNextCollectionItem: page %}
{% if previous or next %}
<section class="margin-top-6 post-pagination">
<div class="grid-container">
<hr class="hr-1-base-lighter">
<div class="grid-row grid-gap">
<div class="grid-col-6">
{% if previous %}
<a href="{{ previous.url | url }}"
class="text-no-underline post-pagination__link"
>
<h2 class="post-pagination__heading">
{% include "svg/icons/arrow-left.svg" %}
Previous Post
</h2>
<p class="measure-1 text-bold text-primary-darkest">{{ previous.data.title }}</p>
</a>
{% endif %}
</div>
<div class="grid-col-6 text-right">
{% if next %}
<a href="{{ next.url | url }}"
class="text-no-underline post-pagination__link"
>
<h2 class="post-pagination__heading">
Next Post
{% include "svg/icons/arrow-right.svg" %}
</h2>
<p class="measure-1 float-right text-bold text-primary-darkest text-right">{{ next.data.title }}</p>
</a>
{% endif %}
</div>
</div>
<hr class="hr-1-base-lighter">
</div>
</section>
{% endif %}
{% include "adjacent_page_links.html" %}

<section class="margin-top-3 margin-bottom-6">
<div class="grid-container">
{% comment %}
Replace the next line with the related posts generator.
TODO: Replace the next line with the related posts generator.
{% endcomment %}
{% assign related_posts = collections.posts | reverse | slice: 0, 3 %}
{% include "featured-posts.html",
Expand Down
17 changes: 7 additions & 10 deletions _includes/layouts/primary.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
main:
class: 'primary-layout'
---

{% assign page_title = page.subnav_title | default: page.title %}

<section class="usa-section section-padding-sm">
<div class="grid-container">
<h1> {{ page.title }} </h1>
{% if page.lead %}
<p class="font-sans-xl line-height-sans-3">{{ page.lead }}</p>
<h1>{{ title }}</h1>
{% if lead %}
<p class="font-sans-xl line-height-sans-3">{{ lead }}</p>
{% endif %}
{% if page.image %}
{% image_with_class page.image "margin-top-4" page.image_alt_text %}
{% if image %}
{% image_with_class image "margin-top-4" image_alt_text %}
{% endif %}
</div>
</section>

{{ content }}
{{ content }}

{% if page.banner_cta %}
{% if banner_cta %}
{% include "banner-cta.html" %}
{% endif %}

12 changes: 9 additions & 3 deletions _includes/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@
{% assign page_title = title | append: ' | 18F ' %}
{% endif %}

{% comment %}
Descriptions are escaped because some contain HTML content which,
left to its own devices, renders in a way that messes up <head>
and looks quite bad.
{% endcomment %}

<title>{{ page_title }}</title>
<meta property="og:title" content="{{ page_title }}" />
<meta name="description" content="{{ description }}" />
<meta property="og:description" content="{{ description }}" />
<meta name="description" content="{{ description | escape }}" />
<meta property="og:description" content="{{ description | escape }}" />

<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@{{ site.twitter }}" />
<meta name="twitter:title" content="{{ title }}" />
<meta name="twitter:description" content="{{ description }}" />
<meta name="twitter:description" content="{{ description | escape }}" />

<meta property="og:type" content="article" />
<link rel="canonical" href="{{ page.url }}" />
Expand Down
8 changes: 2 additions & 6 deletions config/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ const teamLink = (slug) => {
return `<a href="/author/${slug.toLowerCase()}/">${name}</a>`
}

// TODO These all need implementation, they're just placeholders so the site builds at all
// TODO remove the eslint-disable directive after implementation
// TODO This needs implementation, it's just a placeholder for now.
// TODO Remove the eslint-disable directive after implementation
/* eslint-disable */
const weightedSort = (array, weight_name, sort_name) => array
const asRelativeUrl = (url) => url
const matchPosts = (page, property='tags') => []
/* eslint-enable */

const md = markdownIt({ html: true });
Expand All @@ -111,6 +109,4 @@ module.exports = {
teamLink,
markdownify,
weightedSort,
asRelativeUrl,
matchPosts,
};
2 changes: 1 addition & 1 deletion content/pages/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: About 18F
permalink: /about/
layout: styled-container
lead: We help other government agencies build, buy, and share technology products. 18F is a team of designers, software engineers, strategists, and product managers within the General Services Administration. We collaborate with other agencies to fix technical problems, build products, and improve public service through technology.
image: /assets/img/about/gsahq.jpg
image: assets/img/about/gsahq.jpg
image_alt_text: "General Services Administration headquarters"
side_cta: true
subnav_items:
Expand Down
2 changes: 1 addition & 1 deletion content/pages/guides.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Guides
permalink: /guides/
layout: guides
layout: primary
lead: Principles and standards that shape our work
hide_footer_rule: true
---
Expand Down
4 changes: 2 additions & 2 deletions content/pages/projects/products/cloud-gov.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ title: Expedited path to the cloud
subtitle: Reducing the compliance and labor burden of moving to the cloud
permalink: /our-work/cloud-gov/
excerpt: A government-customized hosting platform that takes care of technical infrastructure and security compliance requirements.
image: /assets/img/projects/cg.png
image_accessibility: "The cloud.gov logo of a white star over a black and blue hexagon"
image: assets/img/projects/cg.png
image_alt: "The cloud.gov logo of a white star over a black and blue hexagon"
image_icon: folderwithclock.svg
project_weight: 3
tag: cloud.gov
Expand Down
4 changes: 2 additions & 2 deletions content/pages/projects/products/eregs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ subtitle: A shared service for user-friendly regulations
permalink: /our-work/eregulations/
redirect_from: /project/eregulations/
excerpt: An open-source tool that makes government regulations easier to find, read, and understand.
image: /assets/blog/eregs/regulations-atf-gov.png
image_accessibility:
image: assets/blog/eregs/regulations-atf-gov.png
image_alt:
image_icon:
tag: eregulations
expiration_date:
Expand Down
Loading

0 comments on commit 1171559

Please sign in to comment.