Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const markdownItFootnote = require('markdown-it-footnote');
const { readableDate, htmlDateString, head, min, filterTagList } = require("./config/filters");
const { headingLinks } = require("./config/headingLinks");
const { contrastRatio, humanReadableContrastRatio } = require("./config/wcagColorContrast");
const privateLinks = require ('./config/privateLinksList.js');
const privateLinks = require('./config/privateLinksList.js');
const svgSprite = require("eleventy-plugin-svg-sprite");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const yaml = require("js-yaml");
Expand All @@ -28,16 +28,17 @@ module.exports = function (config) {
config.addPassthroughCopy('robots.txt');

// 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({ './node_modules/@uswds/uswds/dist/js/uswds-init.js': 'assets/js/uswds-init.js' });

// Specific scripts to guides
config.addPassthroughCopy("./assets/**/js/*");
config.addPassthroughCopy("./assets/_common/js/*");
config.addPassthroughCopy("./assets/_common/js/filters.js");
config.addPassthroughCopy("./assets/_common/js/issue-filters.js");

config.addPassthroughCopy({'./assets/_common/_img/favicons/favicon.ico': './favicon.ico' });
config.addPassthroughCopy({'./assets/_common/_img/favicons': './img/favicons' });
config.addPassthroughCopy({ './assets/_common/_img/favicons/favicon.ico': './favicon.ico' });
config.addPassthroughCopy({ './assets/_common/_img/favicons': './img/favicons' });
config.addPassthroughCopy({ './assets/resources/img/agency_logos': './img/agency_logos' });

// Set download paths
// Place files for download in assets/{guide}/dist/{filename.ext}
Expand Down Expand Up @@ -90,7 +91,7 @@ module.exports = function (config) {
return value.toUpperCase();
});

config.addFilter("capitalize", (value) =>{
config.addFilter("capitalize", (value) => {
return value.charAt(0).toUpperCase() + value.slice(1);
});

Expand Down Expand Up @@ -122,15 +123,15 @@ module.exports = function (config) {

// Override Footnote opener
markdownLibrary.renderer.rules.footnote_block_open = () => (
'<section class="footnotes">\n' +
'<ol class="footnotes-list">\n'
'<section class="footnotes">\n' +
'<ol class="footnotes-list">\n'
);

// Add icons for links with locked resources and external links
// https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md
// Token methods: https://github.com/markdown-it/markdown-it/blob/master/lib/token.js#L125
const openDefaultRender = markdownLibrary.renderer.rules.link_open ||
function(tokens, idx, options, env, self) {
function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};

Expand All @@ -139,10 +140,10 @@ module.exports = function (config) {
let prefixIcon = '';
if (privateLinks.some((link) => token.attrGet('href').indexOf(link) >= 0)) {
prefixIcon = '<span class="usa-sr-only"> 18F only, </span>' +
'<svg class="usa-icon margin-top-2px margin-right-2px top-2px" ' +
'aria-hidden="true" role="img">' +
'<use xlink:href="#svg-lock_outline"></use>' +
'</svg>'
'<svg class="usa-icon margin-top-2px margin-right-2px top-2px" ' +
'aria-hidden="true" role="img">' +
'<use xlink:href="#svg-lock_outline"></use>' +
'</svg>'
}

// Check for external URLs. External means any site that is not a federal .gov url
Expand All @@ -166,7 +167,7 @@ module.exports = function (config) {
};

const defaultHtmlBlockRender = markdownLibrary.renderer.rules.html_block ||
function(tokens, idx, options, env, self) {
function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};

Expand Down Expand Up @@ -213,26 +214,26 @@ module.exports = function (config) {

// Also need to add icon links to any html style links
const inlineHTMLDefaultRender = markdownLibrary.renderer.rules.html_inline ||
function(tokens, idx, options, env, self) {
function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};

const linkOpenRE = /^<a[>\s]/i;
markdownLibrary.renderer.rules.html_inline = (tokens, idx, options, env, self) => {
const token=tokens[idx];
const token = tokens[idx];
if (linkOpenRE.test(token.content) && token.content.includes('http')) {
let content = token.content;

//Add private link icon
const hrefRE = /href=\"([^"]*)/;
// get the matching capture group
const contentUrl = content.match(hrefRE)[1];
const contentUrl = content.match(hrefRE)[1];
if (privateLinks.some((privateLink) => contentUrl.indexOf(privateLink) >= 0)) {
const prefixIcon = '<span class="usa-sr-only"> 18F only, </span>' +
'<svg class="usa-icon margin-top-2px margin-right-2px top-2px" ' +
'aria-hidden="true" role="img">' +
'<use xlink:href="#svg-lock_outline"></use>' +
'</svg>'
'<svg class="usa-icon margin-top-2px margin-right-2px top-2px" ' +
'aria-hidden="true" role="img">' +
'<use xlink:href="#svg-lock_outline"></use>' +
'</svg>'
content = content.replace('>', `> ${prefixIcon}`);
tokens[idx].content = content;
}
Expand Down
36 changes: 18 additions & 18 deletions assets/_common/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
});
};

const applySelectFilters = (data, filters, targetType) => {

Check failure on line 33 in assets/_common/js/filters.js

View workflow job for this annotation

GitHub Actions / Run linter

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return Object.entries(filters).reduce((filtered, [key, value]) => {
if (!value || key === 'search') return filtered;

Expand All @@ -54,11 +54,11 @@
return item[key].includes(value);
}
return item[key] === value;
}
}
} else {
let actualKey = key;

switch (key) {

Check failure on line 61 in assets/_common/js/filters.js

View workflow job for this annotation

GitHub Actions / Run linter

Expected a default case
case 'language':
actualKey = 'languages'
break;
Expand Down Expand Up @@ -86,7 +86,7 @@
const [field, direction] = sortBy.split('-');

return [...data].sort((a, b) => {
let aVal, bVal;

Check failure on line 89 in assets/_common/js/filters.js

View workflow job for this annotation

GitHub Actions / Run linter

Split 'let' declarations into multiple statements

switch (field) {
case 'name':
Expand All @@ -110,34 +110,34 @@
}

if (direction === 'desc') {
return aVal < bVal ? 1 : aVal > bVal ? -1 : 0;

Check failure on line 113 in assets/_common/js/filters.js

View workflow job for this annotation

GitHub Actions / Run linter

Do not nest ternary expressions
}
return aVal > bVal ? 1 : aVal < bVal ? -1 : 0;

Check failure on line 115 in assets/_common/js/filters.js

View workflow job for this annotation

GitHub Actions / Run linter

Do not nest ternary expressions
});
};

const processFilters = (state) => {
let filtered = [...state.originalData];
filtered = applySearchFilter(filtered, state.filters.search, state.targetType);
filtered = applySelectFilters(filtered, state.filters, state.targetType);
filtered = sortData(filtered, state.sortBy);

return {
...state,
filteredData: filtered
};
let filtered = [...state.originalData];

filtered = applySearchFilter(filtered, state.filters.search, state.targetType);
filtered = applySelectFilters(filtered, state.filters, state.targetType);
filtered = sortData(filtered, state.sortBy);

return {
...state,
filteredData: filtered
};
};

const createAgencyCardHTML = (agency) => `
<div class="agency-card">
<div class="usa-card__container border-base-light radius-0 border-1px hover:shadow-2 card-list-item">
<div class="usa-card__media usa-card__media--inset display-block pin-top pin-right">
🏥
<img src="../img/agency_logos/${agency.code}.png" class="${agency.code}-logo" alt="${agency.code} logo" width="50"loading="lazy" decoding="async">
</div>
<header class="usa-card__header grid-col-9">
<h3 class="usa-card__heading font-heading-lg margin-top-0">
<a href="/agencies/${agency.code}" target="_blank" rel="noopener noreferrer">${ agency.name }</a>
<a href="/agencies/${agency.code}" target="_blank" rel="noopener noreferrer">${agency.name}</a>
</h3>
</header>
<ul class="width-full usa-card__body font-body-3xs padding-bottom-3 border-bottom-1px border-base-light">
Expand Down Expand Up @@ -168,13 +168,13 @@
if (typeof value === 'string') return [value];
return [];
}

return `
<div class="project-card">
<div class="usa-card__container border-base-light radius-0 border-1px hover:shadow-2 card-list-item">
<header class="usa-card__header">
<h3 class="usa-card__heading font-heading-lg margin-top-0">
<a href="${project.repositoryURL}" target="_blank" rel="noopener noreferrer">${ project.name }</a>
<a href="${project.repositoryURL}" target="_blank" rel="noopener noreferrer">${project.name}</a>
</h3>
<div class="usa-card__subheading font-body-sm text-base-dark">
${project.organization} • ${project.agencyName}
Expand All @@ -188,8 +188,8 @@
<span class="usa-tag usa-tag-big">${project.status}</status>
</div>
${ensureArray(project.languages).slice(0, 3).map(language =>
`<div class="grid-col-auto"><span class="usa-tag">${language}</span></div>`
).join('')}
`<div class="grid-col-auto"><span class="usa-tag">${language}</span></div>`
).join('')}
</div>
</div>
</div>
Expand Down Expand Up @@ -351,7 +351,7 @@
const data = JSON.parse(dataScript.textContent);
initializeFilters(data, targetType);
} catch (error) {
console.error('Error parcing data for filters: ', error);

Check warning on line 354 in assets/_common/js/filters.js

View workflow job for this annotation

GitHub Actions / Run linter

Unexpected console statement
}
}
}
Expand Down
1 change: 1 addition & 0 deletions assets/resources/img/agency_logos/logo_urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ LOGO_URLS:
- https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/US-SocialSecurityAdmin-Seal.svg/359px-US-SocialSecurityAdmin-Seal.svg.png
- https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Seal_of_the_United_States_Federal_Election_Commission.svg/188px-Seal_of_the_United_States_Federal_Election_Commission.svg.png
- https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Seal_of_the_General_Services_Administration.svg/401px-Seal_of_the_General_Services_Administration.svg.png
- https://en.wikipedia.org/wiki/United_States_Department_of_Veterans_Affairs
Binary file added assets/resources/img/agency_logos/va.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions scripts/pull_legacy_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# the commented out links are not valid or cant be found
agencies_links = {
"DoA": "https://usda.gov/code.json",
"USDA": "https://usda.gov/code.json",
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I made this change, we'll need to rerun the scripts. I'll message you guys tmr for your help @sachin-panayil @IsaacMilarky

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, decided to run the scripts using GitHub Action after merging this PR

# "Department of Commerce": "https://www.commerce.gov/code.json",
"DoD": "https://www.code.mil/code.json",
# "Department of Education": "https://ed.gov/code.json",
Expand All @@ -16,7 +16,7 @@
# "Department of Justice": "https://www.justice.gov/d9/code.json",
# "Department of Labor": "https://www.dol.gov/code.json",
# "Department of Transportation": "https://www.transportation.gov/code.json",
"DoT": "https://www.treasury.gov/code.json",
"TREASURY": "https://www.treasury.gov/code.json",
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated agency names to match acronyms list in the original code-gov implementation: https://github.com/GSA/code-gov-data/blob/master/agency_metadata.json

IDEA: I think we should separate out this agency metadata to its own file like how it is done there. I can forsee the frontend also needing to use this data

Copy link
Copy Markdown
Author

@natalialuzuriaga natalialuzuriaga Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDEA for later: Building on top of this, we should display the agency's full name in the agency cards for users that do not know the acronyms. We can use the separate agency metadata file to make this happen @DinneK

"VA": "https://www.va.gov/code.json",
"EPA": "https://www.epa.gov/code.json",
# "National Aeronautics and Space Administration": "https://code.nasa.gov/code.json",
Expand Down
Loading