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

Layouts and menu #20

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Layouts and menu #20

wants to merge 11 commits into from

Conversation

jamesthebrooks
Copy link
Contributor

Changes proposed in this pull request:

  • Layout files migrated over
  • Main menu shows default items as data is migrated in another branch

Copy link

@sknep sknep left a comment

Choose a reason for hiding this comment

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

Don't be afraid to re-name or reorganize some variables to make this nav stuff less annoying to understand

@@ -1,28 +1,33 @@
<li class="usa-collection__item">
<div class="usa-prose padding-right-4">
Copy link

Choose a reason for hiding this comment

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

does the name of this component still make sense if you're pulling the collection item class out? also if these are items in a list, they should still be <li>s

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change was mostly to keep the look and feel of the existing cg-site--I'll defer to you on this--pages way or pre-existing cg-site look? They probably shouldn't be in a list as these are multi-part paginated code blocks. Semantically, it's fine either way.

@@ -0,0 +1,31 @@
{%- assign documentation_navigation=site.documentation_navigation -%}
Copy link

Choose a reason for hiding this comment

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

just curious, why the assignment? you can loop thru site.documentation_navigation on the next line without assigning it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No idea. Not my change, but is a 1:1 from the old site. I'm updating to remove the assignment, but not actually sure where this template is used off the top of my head.

{%- assign documentation_navigation=site.documentation_navigation -%}
{%- for nav_item in documentation_navigation -%}
<h2> {%- if nav_item.icon -%}
<i class='fa fa-fw {{ nav_item.icon }}'></i>
Copy link

Choose a reason for hiding this comment

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

these are the font awesome icon classes. Was it not possible to migrate these to USWDS icons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't even see a reference to this template. Deleting the file.

<a href="https://www.gsa.gov">
{% image_with_class "_img/gsa-logo.svg" "usa-identifier__logo" "GSA logo identifier" %}
</a>
<div class="footer-section-bottom usa-footer__primary-section bg-accent-warm-light border-top border-accent-warm-dark">
Copy link

Choose a reason for hiding this comment

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

can you tell me why you went full utility classes here instead of sticking with the identifier classes? I can't tell what's better about this implementation.

<li class="usa-footer__secondary-link"><a href="/contact">Customer support</a></li>
<li class="usa-footer__secondary-link"><a href="mailto:[email protected]">Business
inquiries</a></li>
<li class="usa-footer__secondary-link"><a href="https://join.tts.gsa.gov/">Join our team</a>
Copy link

Choose a reason for hiding this comment

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

IMO all external (and mailto) links should open in a new window. Also, there's no way you could be familiar with this already, but here's some guidance: https://github.com/cloud-gov/product/blob/main/ContentGuide.md#2-referring-to-external-or-non-government-entities

also join.tts.gsa.gov recently moved to https://tts.gsa.gov/join/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this to override 11ty's default URL filter and am using it {{ somelink | url }} in the template here going forward. Not ready to merge yet.

{% include "menu.html" primary_navigation: pages.navigation.primary secondary_navigation: pages.navigation.secondary %}
{% else %}
{% include "menu.html" primary_navigation: site.primary_navigation secondary_navigation: site.secondary_navigation %}
{% endcase %}
Copy link

Choose a reason for hiding this comment

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

we use assign in so many places, it seems obv to do it here too. would something like this work? note that you'd need to rename the final keys for one of them (primary -> primary_navigation or vice-vera )

{% assign nav = site %}
{% if "pages" %} {% nav = pages.navigation %} {% endif %}
{% include "menu.html" primary_navigation: nav.primary secondary_navigation: nav.secondary %}
  

{% assign toc_content = content | toc | strip | strip_newlines %}
{% assign empty_toc_content = '<ol id="toc" class="section-nav"></ol>' %}

{% if showtoc != false and toc_content != '' and toc_content != empty_toc_content %}
Copy link

Choose a reason for hiding this comment

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

any way to simplify this logic? seems messy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified the logic by moving it to eleventy.js. Compiles fine, but won't be able to feature test until both this and documentation is merged in (PR not yet created).

_includes/layouts/docs.html Show resolved Hide resolved
@@ -6,15 +6,31 @@
This template is for a single page that does not have a date associated with it. For example, an about page.
{% endcomment %}

<div id="main-content" class="usa-layout-docs usa-section">
<div class="usa-layout-docs usa-section {{background}} page-layout">
Copy link

Choose a reason for hiding this comment

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

what's background for, or where is it being set? if it's a color, wouldn't it be bg-{{color}}-{{shade}} like .bg-primary-dark?

Copy link
Contributor Author

@jamesthebrooks jamesthebrooks Nov 1, 2024

Choose a reason for hiding this comment

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

It comes from any given page's front matter so you'd set it there to whatever makes sense.

Example- some-page.html:
background: bg-primary-dark

It's not a convention I came up with... it's either from cg-site or pages-11ty (can't remember).


<div class="grid-row">
<div class="grid-col flex-4"></div>
<div class="grid-col flex-1"><p><a href="{{ site.github_url }}/edit/{{ site.github_branch }}/{{ page.relative_path }}">Suggest edits</a></p></div>
Copy link

Choose a reason for hiding this comment

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

new window!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See .eleventy.js

Copy link

Choose a reason for hiding this comment

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

I don't follow -- can you explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you already saw it by now because of another comment, but here: https://github.com/cloud-gov/site/pull/20/files#diff-c306e0a99961a16f5c5c83996caa0958b94006d97f97475049ea3a08036bb5b0

Eleventy now handles external links on all content and templates during the build through a custom function on the markdown-it plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.eleventy.js has custom code for external links processing now, but I think you already saw that and this comment was earlier.

Copy link

Choose a reason for hiding this comment

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

Eleventy now handles external links on all content and templates during the build through a custom function on the markdown-it plugin.

Hmm... That would work on markdown file content parsed by the markdown engine. This part is in a template. Are you sure it still works that way?

@jamesthebrooks jamesthebrooks force-pushed the chore-layouts-and-menu branch 2 times, most recently from 4bda9e7 to 1ea05ac Compare October 30, 2024 17:01
});

config.addFilter("shouldShowTOC", (content, showToc) => {
return !!showToc && content !== "" && content !== '<ol id="toc" class="section-nav"></ol>';
Copy link

Choose a reason for hiding this comment

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

For every new function/filter you add to the eleventy config, do me a solid and comment what it's for. I can kinda tell but it's always nice to have a little more what/why <3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In another comment on the docs.html page, you asked for the template markup to be simpler and so I moved the logic to here. The new docs.html code looks like this now:

            {% assign toc_content = content | prepTOCContent %}
            {% if toc_content | shouldShowTOC: showtoc %}
            <h2>Table of Contents</h2>
            <div id="table-of-contents">
                {{ toc_content }}
            </div>
            {% endif %}

The markup is simpler now, but the logic still needs to exist somewhere.

Copy link

Choose a reason for hiding this comment

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

If you're going to add custom functions/filters (magic) to eleventy, it needs to be commented in place for other people to understand what it is and how it works. Maybe you thought I meant here on the PR?

const token = tokens[idx];
const hrefAttr = token.attrs ? token.attrs.find(attr => attr[0] === 'href') : null;
if (hrefAttr && /^https?:\/\//.test(hrefAttr[1])) {
token.attrSet('target', '_blank');
Copy link

@sknep sknep Nov 4, 2024

Choose a reason for hiding this comment

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

this is awesome and makes me happy. If you also add a class ("usa-link--external") I think we get the little visual indicator (docs) which would be nice in the article content.

const dom = new JSDOM(content);
const links = dom.window.document.querySelectorAll("a[href^='http']");

links.forEach(link => {
Copy link

Choose a reason for hiding this comment

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

oh maybe this is where to put the external link class? not the above one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be both. One is for markdown and the other is for html files.

Copy link

Choose a reason for hiding this comment

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

Oh. I understand the markdown one but I think doing it for HTML templates might be too heavy-handed overall. Rather than dynamically re-parsing the DOM during the build, i'd rather we just added the _blank etc when we code the HTML.


<div class="grid-row">
<div class="grid-col flex-4"></div>
<div class="grid-col flex-1"><p><a href="{{ site.github_url }}/edit/{{ site.github_branch }}/{{ page.relative_path }}">Suggest edits</a></p></div>
Copy link

Choose a reason for hiding this comment

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

can this one be in a new window too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be automatically from the 11ty build, yes.

@@ -48,3 +48,27 @@ const sideNavExpansion = function (event) {
for (let i = 0; i < sideNavParents.length; i++) {
sideNavParents[i].addEventListener('click', sideNavExpansion, false);
}


Copy link

Choose a reason for hiding this comment

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

Can this be done more simply, with a parent class that handles the toggling? this is a lot of dom manipulation for what is effectively a few CSS changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably, but if I make changes here I can't test them as the sidenav doesn't exist in this branch. We would have to wait until the PR for branch chore-dynamic-sidenav is up for review--that branch and PR does not exist yet. This block is a 1:1 from the Jekyll site with minimal changes to make it continue to function. Please let me know how you'd like me to proceed.

@sknep
Copy link

sknep commented Nov 4, 2024

Something's broken in this build, see the build logs:


2024-10-31 15:23:23 INFO [run-federalist-script] [11ty] Original error stack trace: expected "|" before filter, file:/tmp/work/site_repo/_includes/footer.html, line:16, col:55

2024-10-31 15:23:23 INFO [run-federalist-script] [11ty]    14|                                 </li>

2024-10-31 15:23:23 INFO [run-federalist-script] [11ty]    15|                                 <li class="usa-footer__secondary-link">

2024-10-31 15:23:23 INFO [run-federalist-script] [11ty] >> 16|                                     <a href="{{ mailto:[email protected] | url }}">Business inquiries</a>

2024-10-31 15:23:23 INFO [run-federalist-script] [11ty]                                                              ^

2024-10-31 15:23:23 INFO [run-federalist-script] [11ty]    17|                                 </li>

2024-10-31 15:23:23 INFO [run-federalist-script] [11ty]    18|                                 <li class="usa-footer__secondary-link">

2024-10-31 15:23:23 INFO [run-federalist-script] [11ty]    19|                                     <a href="{{ 'https://join.tts.gsa.gov/' | url }}">Join our team</a>

2024-10-31 15:23:23 ERROR [main] There was a problem running the federalist script, see the above logs for details.

@sknep
Copy link

sknep commented Nov 5, 2024

Is the build still broken? I think that mailto link might not work with your custom HTML link fixer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants