Skip to content
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
51 changes: 3 additions & 48 deletions blocks/github-repos/github-repos.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/**
* Parses the key/value configuration rows authored into the block.
* @param {Element} block The block element
* @returns {Object} Configuration object
*/
function parseConfig(block) {
const config = {};
block.querySelectorAll(':scope > div').forEach((row) => {
const cells = row.querySelectorAll(':scope > div');
if (cells.length === 2) {
const key = cells[0].textContent.trim().toLowerCase();
const value = cells[1].textContent.trim();
if (key) config[key] = value;
}
});
return config;
}

/**
* Creates a status message paragraph and replaces block contents with it.
* @param {Element} block The block element
Expand Down Expand Up @@ -121,19 +103,6 @@ function buildCard(repo) {
* @param {Element} block The block element
*/
export default async function decorate(block) {
const {
username,
limit = '6',
topic = '',
sort = 'updated',
} = parseConfig(block);

if (!username) {
showMessage(block, 'github-repos-error', 'No GitHub username configured.');
return;
}

const limitNum = parseInt(limit, 10) || 6;
const isList = block.classList.contains('list');

// Show loading state while fetching
Expand All @@ -144,27 +113,13 @@ export default async function decorate(block) {
block.replaceChildren(loading);

try {
const response = await fetch(`/data/github-repos/${encodeURIComponent(username)}.json`);
const response = await fetch('/data/github-repos/repos.json');

if (!response.ok) {
throw new Error(`Failed to load repo data: ${response.status}`);
}

let repos = await response.json();

// Client-side topic filter
if (topic) {
repos = repos.filter((repo) => Array.isArray(repo.topics) && repo.topics.includes(topic));
}

// Client-side sort for stars and name
if (sort === 'stars') {
repos.sort((a, b) => b.stargazers_count - a.stargazers_count);
} else if (sort === 'name') {
repos.sort((a, b) => a.name.localeCompare(b.name));
}

repos = repos.slice(0, limitNum);
const repos = await response.json();

if (repos.length === 0) {
showMessage(block, 'github-repos-empty', 'No repositories found.');
Expand All @@ -173,7 +128,7 @@ export default async function decorate(block) {

const ul = document.createElement('ul');
ul.className = isList ? 'github-repos-list' : 'github-repos-grid';
ul.setAttribute('aria-label', `${username} repositories`);
ul.setAttribute('aria-label', 'GitHub Repositories');

repos.forEach((repo) => ul.append(buildCard(repo)));

Expand Down
4 changes: 0 additions & 4 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ h6 {
scroll-margin: 40px;
}

h3 {
margin-bottom: 0.8em;
}

h1 { font-size: var(--heading-font-size-xxl); }
h2 { font-size: var(--heading-font-size-xl); }
h3 { font-size: var(--heading-font-size-l); }
Expand Down