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

Check author image URLs #118

Merged
merged 2 commits into from
Oct 24, 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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
run: yarn
- working-directory: website
run: yarn check-thumbnails
- working-directory: website
run: yarn check-authors
- working-directory: website
run: |
yarn fmt
Expand Down
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"fmt-notes": "ts-node scripts/release-note-format.js",
"compile": "ts-node scripts/compile.ts && prettier --write src/posts.ts",
"check-thumbnails": "ts-node scripts/check-thumbnails.ts",
"check-authors": "ts-node scripts/check-authors.ts",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc",
Expand Down
55 changes: 55 additions & 0 deletions website/scripts/check-authors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import fs from "fs";
import path from "path";
import yaml from "js-yaml";

function fileExistsWithCaseSync(filepath: string): boolean {
const dir = path.dirname(filepath);
if (dir === "/" || dir === ".") {
return true;
}
const filenames = fs.readdirSync(dir);
if (filenames.indexOf(path.basename(filepath)) === -1) {
return false;
}
return fileExistsWithCaseSync(dir);
}

type Author = {
name: string;
title: string;
url: string;
image_url?: string;
};

function readAuthors(): Record<string, Author> {
const authorsFile = fs.readFileSync(
path.join(process.cwd(), "blog", "authors.yml"),
"utf-8",
);
return yaml.load(authorsFile) as Record<string, Author>;
}

function main(): void {
const authors = readAuthors();
const authorsWithInvalidImageUrl: string[] = [];
Object.entries(authors).forEach(([author, authorData]) => {
if (
authorData.image_url &&
!/^https?:\/\//.test(authorData.image_url) &&
!fileExistsWithCaseSync(
path.join(process.cwd(), "static", authorData.image_url),
)
) {
authorsWithInvalidImageUrl.push(author);
}
});

if (authorsWithInvalidImageUrl.length > 0) {
console.log("Found authors with invalid image URLs:");
console.log(authorsWithInvalidImageUrl);
console.log("Please make sure the image exists in the static folder.");
process.exit(1);
}
}

main();
Loading