Skip to content
Draft
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
6 changes: 2 additions & 4 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const BASE_PATH = 'frontend';
const BASE_OUTPUT = '_site';

const getUniqueTaxonomy = (collectionApi, taxonomy) => {
const allItems = collectionApi.getFilteredByGlob(`${BASE_PATH}/posts/*.md`)
.flatMap((item) => item.data[taxonomy] || []);
const allItems = collectionApi.getFilteredByGlob(`${BASE_PATH}/posts/*.md`).flatMap((item) => item.data[taxonomy] || []);
return [...new Set(allItems)];
};

Expand All @@ -22,8 +21,7 @@ module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy(`${BASE_PATH}/assets`);

eleventyConfig.addCollection('posts', (collectionApi) => {
return collectionApi.getFilteredByGlob(`${BASE_PATH}/posts/*.md`)
.sort((a, b) => b.date - a.date);
return collectionApi.getFilteredByGlob(`${BASE_PATH}/posts/*.md`).sort((a, b) => b.date - a.date);
});

eleventyConfig.addCollection('categories', (collectionApi) => {
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/lerna.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: ['20.x', '22.x']
# Use Node 18 LTS and Node 20 (avoid Node 22 which showed wasm/memory failures
# on the macos runner in CI). Add back 22.x when upstream issues are resolved.
node-version: ['18.x', '20.x']
steps:
- uses: actions/checkout@v5

Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/link-check-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check Links (Action)

on:
pull_request:
paths:
- '**.md'

jobs:
link-check:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Link Checker
uses: lycheeverse/lychee-action@v1
with:
args: |
--verbose
--no-progress
--accept 200,429
--timeout 30
--max-redirects 5
--base https://brisbanesocialchess.github.io
"**/*.md"
fail: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59 changes: 59 additions & 0 deletions .github/workflows/link-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Check Markdown Links

on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- '**.md'
- '.github/workflows/link-check.yml'
- '.markdown-link-check.json'

jobs:
markdown-link-check:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies
run: npm install markdown-link-check

- name: Check links in markdown files
run: npx markdown-link-check --config .markdown-link-check.json --verbose .
continue-on-error: true
id: link-check

- name: Comment on PR if links are broken
if: steps.link-check.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;

const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const comment = `## 🔗 Broken Links Detected

The link checker found some broken links in your markdown files. Please review and fix them:

- Check the workflow logs for details: ${runUrl}
- Relative links starting with \`/\` are automatically converted to \`https://brisbanesocialchess.github.io/\`
- Make sure all internal links point to existing files/pages

You can run the link checker locally with: \`npm run check-links\``;

github.rest.issues.createComment({
issue_number,
owner,
repo,
body: comment
});
39 changes: 39 additions & 0 deletions .markdown-link-check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"ignorePatterns": [
{
"pattern": "^http://localhost"
},
{
"pattern": "^https://localhost"
},
{
"pattern": "^#%"
},
{
"pattern": "^mailto:"
},
{
"pattern": "^\\{\\{"
}
],
"replacementPatterns": [
{
"pattern": "^/",
"replacement": "https://brisbanesocialchess.github.io/"
}
],
"httpHeaders": [
{
"urls": ["https://github.com"],
"headers": {
"Accept": "text/html",
"User-Agent": "Mozilla/5.0"
}
}
],
"aliveStatusCodes": [200, 206, 429],
"timeout": "15s",
"retryOn429": true,
"retryCount": 3,
"fallbackRetryDelay": "30s"
}
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ repos:
entry: npx lerna run test -- --run
language: system
pass_filenames: false
- id: markdown-link-check
name: Run markdown-link-check
description: Check markdown files for broken links using .markdown-link-check.json
entry: markdown-link-check
language: node
types: [markdown]
args: ['--config', '.markdown-link-check.json']
additional_dependencies: ['[email protected]']
- id: prettier
name: Run prettier
description: format files with prettier
Expand Down
120 changes: 120 additions & 0 deletions frontend/LINK_CHECKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Link Checker Documentation

This document explains how the broken link checker works in the Brisbane Social Chess website.

## Overview

The project uses `markdown-link-check` to automatically detect broken links in markdown files. This helps maintain link integrity and provides a better user experience.

## Configuration

The link checker is configured via `.markdown-link-check.json`:

### Key Features

- **Relative Link Conversion**: Links starting with `/` are automatically converted to `https://brisbanesocialchess.github.io/`
- **Ignored Patterns**:
- Localhost links (`http://localhost`, `https://localhost`)
- URL-encoded anchor links (`#%...`)
- Mailto links (`mailto:`)
- Template syntax (links starting with `{{`)
- **Retry Logic**: Automatically retries on 429 (rate limit) responses
- **Timeout**: 15-second timeout for link checks
- **User-Agent**: Proper headers for GitHub links

## Usage

### Local Development

```bash
# Check all markdown files (cross-platform)
npm run check-links

# Check with verbose output (shows status codes)
npm run check-links-verbose

# Run the CLI directly on specific files
npx markdown-link-check --config .markdown-link-check.json README.md frontend/LINK_CHECKER.md
```

### What Gets Checked

The link checker automatically scans all `.md` files in the repository while excluding:

- `node_modules/` directories (including in packages)
- `.git/` directory
- Any subdirectories within excluded paths

The script uses a Node.js helper (`scripts/check-links.js`) to ensure cross-platform compatibility and proper directory exclusion.

### Link Types Handled

1. **External URLs**: Fully qualified URLs (e.g., `https://github.com`)
2. **Relative Links**: Links starting with `/` (converted to full URLs)
3. **File Links**: Links to other markdown files (e.g., `./README.md`)
4. **Anchor Links**: Internal page anchors (e.g., `#section-name`)
5. **Ignored Links**: Mailto, localhost, and encoded anchors

## GitHub Actions Integration

Two workflows are available:

### 1. Custom Workflow (`.github/workflows/link-check.yml`)

- Runs on pull requests that modify markdown files
- Uses the same configuration as local development
- Comments on PRs when broken links are found
- Provides detailed error information

### 2. Lychee Action (`.github/workflows/link-check-action.yml`)

- Alternative implementation using `lychee-action`
- Simpler setup but less customizable
- Also runs on markdown file changes

Comment on lines +60 to +74
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This section describes two GitHub Actions workflows that don't seem to be part of this pull request or the repository yet. Documenting functionality that doesn't exist can be confusing for developers. It's best to keep documentation aligned with the current state of the codebase. I'd recommend removing this section for now. It can be added back in a separate pull request when the workflows are actually implemented.

## Troubleshooting

### Common Issues

1. **404 Errors on Anchor Links**: Make sure the target heading exists in the file
2. **Rate Limiting**: The checker automatically retries on 429 responses
3. **Timeout Issues**: Increase timeout in configuration if needed

### False Positives

Some links may appear broken but are actually valid:

- **Mailto links**: Intentionally ignored
- **Encoded anchors**: Links with emojis in headings are ignored
- **Local development links**: Localhost URLs are ignored

## Best Practices

1. **Use Relative Links**: For internal pages, use `/page-name` format
2. **Test Locally**: Run `npm run check-links` before committing
3. **Fix Broken Links**: Address any broken links found by the checker
4. **Update Configuration**: Modify `.markdown-link-check.json` if needed

## Configuration Reference

The full configuration is available in `.markdown-link-check.json`. This file controls how the link checker operates, including which patterns to ignore, how to handle relative links, retry logic, and timeout settings.

Key configuration options:

- `ignorePatterns`: Patterns for links to skip (localhost, mailto, encoded anchors)
- `replacementPatterns`: Rules for converting relative links to absolute URLs
- `httpHeaders`: Custom headers for specific domains (like GitHub)
- `aliveStatusCodes`: HTTP status codes considered valid (200, 206, 429)
- `timeout`: How long to wait for responses (15s)
- `retryOn429`: Automatically retry on rate limit responses
- `retryCount`: Number of retry attempts (3)
- `fallbackRetryDelay`: Delay between retries (30s)

## Contributing

When adding new markdown files or links:

1. Run the link checker locally
2. Fix any broken links
3. Ensure relative links use the correct format
4. Test that anchor links point to existing headings
Loading
Loading