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

Add resource workflow + page #241

Merged
merged 9 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions .github/workflows/update-resource-page.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Update resource page

on:
workflow_dispatch:
schedule:
- cron: '0 8 * * *'

jobs:
run-r-script:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# This helps override the branch protection later
token: ${{ secrets.SUDO_GITHUB_TOKEN }}
- name: Collect resource data
run: node _scripts/resource-retrieval-graphql Resources
- name: Re-render resource page
run: quarto render resource.qmd
- uses: EndBug/add-and-commit@v9
with:
author_name: epiverse-trace-bot
author_email: epiverse-trace-bot@users.noreply.github.com
message: "Update `./resources/`"
add: './resources/'
8 changes: 5 additions & 3 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ website:
href: get-involved.qmd
- text: Blog
menu:
- text: All
Copy link
Member

Choose a reason for hiding this comment

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

Should this be something like "all blog posts" or something? Because it doesn't include presentations, i.e., not all publications.

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand the confusion - I moved the presentations back into the main bar for now and will come with a proposal. May also be helped by the multi-selection you mentioned (which is tracked over in #244).

url: "/blog.html"
- text: Articles
url: "/blog.html#category=R"
- text: Release notes
url: "/blog.html#category=new-release"
- text: All
url: "/blog.html"
- presentations.qmd
- text: Presentations
href: presentations.qmd
- href: resources.qmd
- text: Learn
href: learn.qmd
- text: About
Expand Down
100 changes: 100 additions & 0 deletions _scripts/resource-retrieval-graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const fs = require("fs");

// PAT only needs access to read issues
const pat = process.env.GITHUB_TOKEN;

const arg = process.argv[2];
// Default to the announcements category
const category = arg ? arg : "Announcements";

async function fetchDiscussions(afterCursor) {
const query = `
{
repository(owner: "epiverse-trace", name: "epiverse-trace.github.io") {
discussions(first: 100, after: ${afterCursor ? '"' + afterCursor + '"' : null}, orderBy: {field: CREATED_AT, direction: DESC}) {
nodes {
id
title
url
createdAt
labels(first: 10) {
nodes {
name
}
}
author {
login
}
category {
name
}
upvoteCount
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
`;

const response = await fetch("https://api.github.com/graphql", {
method: "POST",
headers: {
Authorization: `bearer ${pat}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ query }),
});

const json = await response.json();
const discussions = json.data.repository.discussions.nodes;
const { endCursor, hasNextPage } = json.data.repository.discussions.pageInfo;

if (hasNextPage) {
return discussions.concat(await fetchDiscussions(endCursor));
} else {
return discussions;
}
}

// When there are no next pages, process the responses
fetchDiscussions(null).then((discussions) => {
let filteredDiscussions = discussions.filter(
(discussion) => discussion.category.name === category,
);

// Prepare the array for processing
filteredDiscussions = filteredDiscussions.map((discussion) => ({
...discussion,
author: discussion.author.login,
category: discussion.category.name,
labels: discussion.labels.nodes.map((label) => label.name).join(", "),
}));

// Ensure directory exists
try {
fs.mkdirSync('resources/');
} catch {
console.log('resources/ already exists')
}

filteredDiscussions.forEach((discussion) => {
fs.writeFile(
`resources/${discussion.id}.qmd`,
`---
title: "${discussion.title.replace(/"/g, '')}"
url: "${discussion.url}"
date: "${discussion.createdAt.substr(0,10)}"
author: ${discussion.author}
categories: [${discussion.labels}]
upvotes: ${discussion.upvoteCount}
---`,
(err) => {
if (err) throw err;
console.log(`resources/${discussion.id}.qmd saved`);
},
);
});
});
29 changes: 29 additions & 0 deletions custom_listing_resources.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
```{=html}
<div class="archive list">
<% for (const item of items) { %>
<div class="quarto-post image-right" <%= metadataAttrs(item) %>>
<div class="body">
<h3 class="no-anchor listing-title"><a href="<%- item.url %>" class="no-external"><%= item.title %></a></h3>
<div class="listing-subtitle"><a href="<%- item.url %>" class="no-external"><%= item.subtitle %></a></div>
</div>
<div class="metadata">
<div class="ratings">
<span class="rating listing-upvotes rating-upvotes-<%= item.upvotes %> ">👍 <%= item.upvotes %></span>
</div>
<% if (item.categories) { %>
<span class="listing-categories">
<% for (const category of item.categories) { %>
<span class="listing-category" onclick="window.quartoListingCategory('<%=category%>'); return false;"><%= category %></span>
<% } %>
</span>
<% } %>
<span class="archive-item-date">
<span class="listing-date">
<%= item.date %>
</span>
</span>
</div>
</div>
<% } %>
</div>
```
21 changes: 21 additions & 0 deletions resources.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: "Resources"
listing:
contents: resources
sort:
- "upvotes desc"
type: default
categories: true
filter-ui: true
sort-ui:
- date
- upvotes
template: custom_listing_resources.ejs
field-types:
upvotes: number
page-layout: full
title-block-banner: true
comments: false
---

On this page, you can find resources shared on our discussion forum. [Submit your own](https://github.com/orgs/epiverse-trace/discussions/new?category=resources) and upvote the ones you like on GtiHub!
8 changes: 8 additions & 0 deletions resources/D_kwDOIcolP84AZPXq.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: "How to Run GitHub Actions Locally Using the act CLI Tool"
url: "https://github.com/orgs/epiverse-trace/discussions/245"
date: "2024-05-06"
author: chartgerink
categories: []
upvotes: 1
---
Loading