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

Refactor projects page #294

Merged
merged 24 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix sort functionality
Signed-off-by: Dinne Kopelevich <dinne.kopelevich@gsa.gov>
  • Loading branch information
DinneK committed Dec 4, 2024
commit 9953c78bf833129e193fe471e45d487da7950ff7
2 changes: 1 addition & 1 deletion app/.eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = function (eleventyConfig) {
"stroke-width": 2,
})

const pathPrefix = process.env.NODE_ENV === "production" ? "/metrics" : ""
const pathPrefix = process.env.NODE_ENV.includes("production") ? "/metrics" : ""

return {
dir: {
Expand Down
5 changes: 5 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"start:eleventy": "eleventy --serve",
"start:rollup": "rollup --config rollup.config.mjs -w",
"start:postcss": "postcss ./src/css -d ./site/_includes/css -w",
"prod": "NODE_ENV=test-production run-s -l prod:*",
"prod:clean": "rm -rf dist",
"prod:rollup": "rollup --config rollup.config.mjs --bundleConfigAsCjs",
"prod:postcss": "postcss ./src/css -d ./site/_includes/css",
"prod:eleventy": "eleventy --serve",
"build": "NODE_ENV=production run-s -l build:*",
"build:clean": "rm -rf dist",
"build:rollup": "rollup --config rollup.config.mjs --bundleConfigAsCjs",
Expand Down
2 changes: 1 addition & 1 deletion app/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
plugins: [
require("postcss-import"),
require("autoprefixer"),
...(process.env.NODE_ENV === "production"
...(process.env.NODE_ENV.includes("production")
? [
require("cssnano"),
require("@fullhuman/postcss-purgecss")({
Expand Down
2 changes: 1 addition & 1 deletion app/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default [
resolve(),
babel(),
commonjs(),
...(process.env.NODE_ENV === "production" ? [terser()] : []),
...(process.env.NODE_ENV.includes("production") ? [terser()] : []),
],
},
]
11 changes: 6 additions & 5 deletions app/site/_data/site.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const production = process.env.NODE_ENV === "production"
const isProduction = process.env.NODE_ENV.includes("production")
const isTest = process.env.NODE_ENV.includes("test")

const host = production ? "https://dsacms.github.io" : "http://0.0.0.0:8080"
const host = (isProduction && !isTest) ? "https://dsacms.github.io" : "http://localhost:8080"

// For modifying the <base> tag
const baseurl = production ? "/metrics" : ""
const baseurl = isProduction ? "/metrics" : ""

module.exports = {
name: "CMS Metrics Website",
Expand All @@ -13,8 +14,8 @@ module.exports = {
baseurl,
url: `${host}${baseurl}`,
domain: (host || "").replace("https://", ""),
production,
robots: production,
production: isProduction,
robots: isProduction,
locale: "en-US",
// TODO: Add nav elements for deployment
nav: [{ url: "/about/", label: "About" }],
Expand Down
4 changes: 2 additions & 2 deletions app/site/_includes/nav.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<nav aria-label="Primary navigation" class="usa-nav">
<button type="button" class="usa-nav__close">
<svg class="usa-icon--size-7" aria-hidden="true" focusable="false" role="img">
<use xlink:href="/assets/img/sprite.svg#close"></use>
<use href="{{ site.baseurl }}/assets/img/sprite.svg#close"></use>
</svg>
</button>
<ul class="usa-nav__primary usa-accordion">
Expand All @@ -32,7 +32,7 @@
focusable="false"
role="img"
>
<use xlink:href="/assets/img/sprite.svg#menu">
<use href="{{ site.baseurl }}/assets/img/sprite.svg#menu">
</svg>
</button>
<ul id="basic-nav-section-one" class="usa-nav__submenu">
Expand Down
4 changes: 2 additions & 2 deletions app/site/index.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ layout: base
<div class="usa-card__container">
<div class="home-icon-container">
<svg class="usa-icon--size-5" aria-hidden="true" focusable="false" role="img">
<use xlink:href="/assets/img/sprite.svg#groups"></use>
<use href="{{ site.baseurl }}/assets/img/sprite.svg#groups"></use>
</svg>
</div>
<div class="usa-card__header">
Expand All @@ -50,7 +50,7 @@ layout: base
<div class="usa-card__container">
<div class="home-icon-container">
<svg class="usa-icon--size-5" aria-hidden="true" focusable="false" role="img">
<use xlink:href="/assets/img/sprite.svg#folder_open"></use>
<use href="{{ site.baseurl }}/assets/img/sprite.svg#folder_open"></use>
</svg>
</div>
<div class="usa-card__header">
Expand Down
22 changes: 6 additions & 16 deletions app/site/projects.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ layout: base

<script type="module" src="{{ "/assets/js/projects.js" | url }}"></script>
<span style="display:none;" id="metrics">
{{projects | json }}
{{ projects | json }}
</span>
<span style="display:none;" id="org-data">
{{organizations | json }}
{{ organizations | json }}
</span>
<span style="display:none;" id="site-data">
{{ site | json }}
</span>
<div class="grid-container-projects">
<div class="description-styling">
Expand Down Expand Up @@ -111,19 +114,6 @@ layout: base
<div class="search-block">
<div class="search-and-sort">

<!-- <div class="search-container">
<label class="usa-label" for="filter-input">Search</label>
<div class="usa-input-group width-full maxw-none border-base-light">
<div class="usa-input-prefix" aria-hidden="true">
<svg aria-hidden="true" role="img" focusable="false" class="usa-icon">
<use xlink:href={{ "/assets/img/sprite.svg#search"| url }} ></use>
</svg>
</div>
<input class="usa-input--lg" id="filter-input" name="filter-input">
</div>
</div> -->


<section aria-label="Small search component">
<form class="usa-search usa-search--small" role="search" id="search-form">
<label class="usa-sr-only" for="search-input">Search</label>
Expand All @@ -136,7 +126,7 @@ layout: base
/>
<button class="usa-button" type="submit">
<img
src="/assets/img/usa-icons-bg/search--white.svg"
src="{{ site.baseurl }}/assets/img/usa-icons-bg/search--white.svg"
class="usa-search__submit-icon"
alt="Search"
/>
Expand Down
6 changes: 3 additions & 3 deletions app/src/js/projects.js
DinneK marked this conversation as resolved.
Show resolved Hide resolved
DinneK marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { reportHeadingTemplate, projectCardTemplate, renderProjectCards } from "./templates";
import { reportHeadingTemplate, projectCardTemplate } from "./templates";
import DOMPurify from 'dompurify';

const projectsData = document.getElementById('metrics').textContent;
const orgsData = document.getElementById('org-data').textContent;
const parsedOrgsData = JSON.parse(orgsData);
const siteData = JSON.parse(document.getElementById('site-data').textContent);
const parsedProjectsData = JSON.parse(projectsData);
const filtersContainer = document.querySelector('.filters-container');
const templateDiv = document.getElementById('content-container');
Expand Down Expand Up @@ -112,8 +113,6 @@ function sortCards(isDescending = false) {

function createProjectCards() {
templateDiv.innerHTML = ''

// const allProjects = Object.keys(projects).flatMap(org => projects[org].map(project => ({ ...project, org })));

const allProjects = (filteredProjects || parsedProjectsData).map((project) => ({
...project,
Expand Down Expand Up @@ -151,6 +150,7 @@ function createProjectCards() {
projectSectionsTemplate.appendChild(projectCards);

groupedByOrg[org].forEach(repoData => {
repoData.url = siteData.baseurl;
const projectCard = document.createElement('li');
projectCard.className = 'usa-card project-card tablet:grid-col-12';
projectCard.id = repoData.name;
Expand Down
3 changes: 1 addition & 2 deletions app/src/js/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ export const reportHeadingTemplate = function(data) {
}

export function projectCardTemplate(data) {
const baseUrl = window.location.hostname === "dsacms.github.io" ? '/metrics' : ""
const description = data.description !== null ? data.description : ""
return `
<div class="usa-card-outer outer-project-template">
<div class="usa-card-middle">
<a href="${ baseUrl }/${ data.owner }/${ data.name }/" class="href-home">
<a href="${ data.url }/${ data.owner }/${ data.name }/" class="href-home">
natalialuzuriaga marked this conversation as resolved.
Show resolved Hide resolved
<div class="usa-card__container container-project-template">
<div class="text-container-project-template">
<div class="usa-card__header header-project-template">
Expand Down