Skip to content

Commit

Permalink
adding support for last-modified (#759)
Browse files Browse the repository at this point in the history
* adding support for last-modified

this includes a new "include" that will allow us to set a boolean, set_last_modified to true on any
page to automatically add a last modified date to the bottom left, courtesy of the GitHub commits api. Given that
we want to customize either 1. the div id, 2. the repository used (and in this case) 3. the path, those are
also exposed as variables to customize (e.g., current set for the code of conduct and governance). Including these
changes to templates I have also added the last modified date to be included on most about pages and working group
pages, and double checked that the dates are accurate. Thanks Peter for the great idea!

Signed-off-by: vsoch <vsoch@users.noreply.github.com>

* Removing last modified in governanace

Co-authored-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch and vsoch committed Mar 18, 2022
1 parent f9cd52a commit 4c86fb8
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 3 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,34 @@ and then embed (note that "embed" is in the url) and the title is a title of you
choosing. You are not required to include a title, and it will default to a generic
"YouTube video player."

### 7. How do I add a "Last Modified:" date?

All of our pages come ready to go to add a "last modified" date, which will default to the bottom
right of the page. This means to add a last modified date to a page, simply update the frontend matter as follows:

```yaml
set_last_modified: true
```

If you want to change the default div id (e.g., adding your own html div with a specific ID and not using the default
provided) you can add that too:

```yaml
set_last_modified: true
last_modified_id: last-modified
```

And finally, if the repository you are retrieving the file from is different than the repository here, define the repository
and path (relative to the root)

```yaml
set_last_modified: true
last_modified_id: last-modified
last_modified_repo: USRSE/documents
last_modified_path: governance.md
```

If you have any questions, please don't hesitate to [open an issue](https://github.com/USRSE/usrse.github.io)

## Tests

Expand Down
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ hero_line_two: A community of people who make research software happen.
# social media
twitter: us_rse
github_org: USRSE
github_repo: usrse.github.io
linkedin: company/us-rse/

# Twitter card for meta tags
Expand Down
21 changes: 21 additions & 0 deletions _includes/last-modified.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script>
function setLastModified() {
if (document.getElementById('{% if page.last_modified_id %}{{ page.last_modified_id }}{% else %}last-modified{% endif %}')) {
fetch("https://api.github.com/repos/{% if page.last_modified_repo %}{{ page.last_modified_repo }}{% else %}{{ site.github_org }}/{{ site.github_repo }}{% endif %}/commits?path={% if page.last_modified_path %}{{ page.last_modified_path }}{% else %}{{ page.path }}{% endif %}")
.then((response) => {
return response.json();
})
.then((commits) => {
var modified = commits[0]['commit']['committer']['date'].slice(0,10);
console.log(modified)
document.getElementById('last-modified').textContent = "Last Modified: " + modified;
})
.catch((error) => {
console.log(error)
});
}
}
$(document).ready(function(){
setLastModified();
})
</script>
7 changes: 4 additions & 3 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
</div>{% endif %}
<div class="column">
{{ content }}
{% comment %}Add the last modified default ID (floating to right) unless the page defines a custom one {% endcomment %}
{% unless page.last_modified_id %}<div style="float:right; margin-top:25px" id="last-modified"></div>{% endunless %}
</div>
</div>
</div>
</section>
{% unless page.hide_footer %}
{% include footer.html %}
{% endunless %}
{% unless page.hide_footer %}{% include footer.html %}{% endunless %}
{% include footer-scripts.html %}
{% if page.set_last_modified %}{% include last-modified.html %}{% endif %}
</body>
</html>
1 change: 1 addition & 0 deletions pages/about/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ title: About US-RSE
description: About the US-Research Software Engineer Association
menubar: about
permalink: /about/
set_last_modified: true
---

The US Research Software Engineer Association (US-RSE) is a community-driven effort focused on the increasingly important role of the [Research Software Engineer]({{ site.baseurl }}/what-is-an-rse/).
Expand Down
3 changes: 3 additions & 0 deletions pages/about/code-of-conduct.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ title: Code of Conduct
permalink: /about/code-of-conduct/
subtitle: The US-RSE Association Code of Conduct.
menubar: about
set_last_modified: true
last_modified_repo: USRSE/documents
last_modified_path: code-of-conduct.md
---

<div id="code-of-conduct" style="display:none"></div>
Expand Down
1 change: 1 addition & 0 deletions pages/about/dei-mission-statement.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ subtitle: Diversity, Equity, and Inclusion at US-RSE
permalink: /about/dei-mission/
menubar: about
menubar_toc: true
set_last_modified: true
---

#### Diversity, Equity, and Inclusion at US-RSE
Expand Down
1 change: 1 addition & 0 deletions pages/about/election.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: US-RSE Steering Committee Elections
permalink: /about/election/
menubar: about
menubar_toc: true
set_last_modified: true
---

The 2021 US-RSE Steering Committee elections are happening this December.
Expand Down
1 change: 1 addition & 0 deletions pages/about/finances.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ layout: page
title: US-RSE Financial Status
permalink: about/finances/
menubar: about
set_last_modified: true
---

### Open Collective Foundation Member
Expand Down
1 change: 1 addition & 0 deletions pages/about/mission.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: Goals and Aims of the US-RSE Association
permalink: /about/mission/
menubar: about
menubar_toc: true
set_last_modified: true
---

The US-RSE Association is centered around four main goals. We aim
Expand Down
1 change: 1 addition & 0 deletions pages/about/steering-committee.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ permalink: /about/steering-committee/
subtitle: The US-RSE Association is community driven and organized.
menubar: about
menubar_toc: true
set_last_modified: true
---


Expand Down
1 change: 1 addition & 0 deletions pages/about/working-groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ permalink: /about/working-groups/
subtitle: Focused groups to tackle community topics
menubar: about
menubar_toc: true
set_last_modified: true
---

<h3><a href="{{ site.baseurl }}/wg/dei/">Diversity, Equity, and Inclusion (DEI)</a></h3>
Expand Down
1 change: 1 addition & 0 deletions pages/wg/dei.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ layout: page
title: Diversity, Equity, & Inclusion Working Group
subtitle:
permalink: /wg/dei/
set_last_modified: true
---

# Overview
Expand Down
1 change: 1 addition & 0 deletions pages/wg/education_training.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ layout: page
title: Education & Training Working Group
subtitle:
permalink: /wg/education_training/
set_last_modified: true
---

# Overview
Expand Down
1 change: 1 addition & 0 deletions pages/wg/outreach.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ layout: page
title: Outreach Working Group
subtitle:
permalink: /wg/outreach/
set_last_modified: true
---

# Overview
Expand Down
1 change: 1 addition & 0 deletions pages/wg/website.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ layout: page
title: Website Working Group
subtitle:
permalink: /wg/website/
set_last_modified: true
---

# Overview
Expand Down

0 comments on commit 4c86fb8

Please sign in to comment.