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

Automated README.md generator & individual item files #92

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4934487
CSJ script to build the README.md automatically from the files that a…
CamKem Mar 17, 2024
42138ee
Added the "gray-matter" yaml parsing dependency.
CamKem Mar 17, 2024
13f519e
Added the partials needed for building the README.md
CamKem Mar 17, 2024
9b5883f
Removed comments and added the link in contents for the contribution …
CamKem Mar 17, 2024
d72641a
Added interview links
CamKem Mar 17, 2024
b98267e
Parsed the README.md with a script to automatically generate the md f…
CamKem Mar 17, 2024
a01e7aa
Updated with the data parsed from the original README.md
CamKem Mar 17, 2024
5a85b6f
removed original README.md to add generated one
CamKem Mar 17, 2024
5f45ec8
Updated with parsed README.md data
CamKem Mar 17, 2024
8d1a6af
Updated sections.md to reflect the correct category names, for when t…
CamKem Mar 17, 2024
fc4d1f1
Fixed yaml syntax so it builds correctly.
CamKem Mar 17, 2024
fb67e1e
Created the example.md file so people know how to add their link to t…
CamKem Mar 17, 2024
2f8e6d9
Added the introduction.md for building
CamKem Mar 17, 2024
03759bc
Allowed for corrected building based on category
CamKem Mar 17, 2024
35974bf
Updated pallyy.md fully to show what details could be added
CamKem Mar 17, 2024
63bf290
Fixed the inconsistency with the ampersands/and in the contents vs he…
CamKem Mar 17, 2024
070efb6
Build new README.md using the automated script
CamKem Mar 17, 2024
6dd2547
Added workflow for github action to generate the README.md each time …
CamKem Mar 17, 2024
feb0a4a
Added solid.md to test the github action to automatically build the R…
CamKem Mar 17, 2024
4634e7f
Merge pull request #1 from CamKem/read-me-generator-tester
CamKem Mar 17, 2024
1edf760
Revert "Added solid.md to test the github action for auto building RE…
CamKem Mar 17, 2024
8e480f4
Merge pull request #2 from CamKem/revert-1-read-me-generator-tester
CamKem Mar 17, 2024
45398d8
changed working directory in the GitHub action.
CamKem Mar 17, 2024
a7a0dce
added solid.md to test the github action on merge
CamKem Mar 17, 2024
86d2229
Merge pull request #3 from CamKem/new-item-built-test
CamKem Mar 17, 2024
6eef097
Revert "Testing the github action"
CamKem Mar 17, 2024
84add72
Merge pull request #4 from CamKem/revert-3-new-item-built-test
CamKem Mar 17, 2024
a4afd7a
Corrected mistake in the working directory
CamKem Mar 17, 2024
1712bb6
Added solid.md for final test of the github action
CamKem Mar 17, 2024
f67e424
Merge pull request #5 from CamKem/read-me-generator-final-test
CamKem Mar 17, 2024
244987b
changed again
CamKem Mar 17, 2024
40d668c
changed again
CamKem Mar 17, 2024
59b919e
Merge pull request #6 from CamKem/read-me-generator-solid
CamKem Mar 17, 2024
479d43d
Update README.md
actions-user Mar 17, 2024
d898362
Fixed ampersands causing issues with contents links targeting categor…
CamKem Mar 17, 2024
62ec32b
Added function to sanitise the links being built to prevent any broke…
CamKem Mar 17, 2024
a9b513e
remove the testing branch from the targeted branches in the GH Action…
CamKem Mar 17, 2024
85ed60c
parsed items from merged PRs to build md files & rebuilt README.md wi…
CamKem Mar 17, 2024
c1b5103
Updated contributing.md to reflect the new instructions for adding an…
CamKem Mar 17, 2024
c0021c1
Updated the example.md to give a better example of what should be add…
CamKem Mar 17, 2024
ef73774
Added "website builders" section recently merged
CamKem Mar 18, 2024
45a180e
Built new items recently merged & rebuilt the README.md
CamKem Mar 18, 2024
9ff5c63
Build publer.md item file & rebuilt README.md to stay in sync
CamKem Mar 18, 2024
584cc23
Added hosting coolify.md & hetzner.md, that I missed & rebuilt the RE…
CamKem Mar 18, 2024
d9d0a00
Correct url typo for the added items
CamKem Mar 18, 2024
afcc6ed
Rebuild README.md with url typo fixed.
CamKem Mar 18, 2024
c25e4d9
parsed-items using code for simple-analytics interview & rebuild READ…
CamKem Mar 20, 2024
8447643
Commit merged commits from upstream remote origin & updated files to …
CamKem Mar 25, 2024
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
37 changes: 37 additions & 0 deletions .github/workflows/build-readme.yml
CamKem marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build README.md

on:
pull_request:
types: [closed]
branches:
- main

jobs:
build:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Install dependencies
run: npm ci
working-directory: ./.website

- name: Build README
run: npm run build-readme
working-directory: ./.website

- name: Commit and push changes
run: |
git diff
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -am "Update README.md" || echo "No changes to commit"
git push
131 changes: 131 additions & 0 deletions .website/build-readme.cjs
CamKem marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// This script is used to build the README file by combining the header, sections, and contribute files with the items files.

const fs = require('fs');
const path = require('path');
const matter = require('gray-matter');

// Function to sanitize names for use in links
function sanitizeName(name) {
name = name.trim()
.toLowerCase()
.replace(/ /g, '-')
.replace(/&/g, 'and')
.replace(/[^\w-]+/g, '');
return encodeURIComponent(name)
}

// Start the content with the header
let content = fs.readFileSync(path.join(__dirname, '../partials/header.md'), 'utf8');

// Read the sections file
const sectionsFilePath = path.join(__dirname, '../partials/sections.md');
const sectionsFileContent = fs.readFileSync(sectionsFilePath, 'utf-8');
const {sections, categories} = matter(sectionsFileContent).data;

// Add the table of contents
content += '\n## Table of Contents\n';
for (const section of sections) {
content += '- [' + section.name + '](#' + sanitizeName(section.name) + ')\n';
if (section.name === 'Tools') {
for (const category of categories) {
content += ' - [' + category.name + '](#' + sanitizeName(category.name) + ')\n';
}
}
}
// Add the contribute link to the table of contents
content += '- [Contribute](#contribute)\n';
content += '\n';

// Add the sections to the content
for (const section of sections) {
content += '## ' + section.name + '\n';
if (section.description) {
content += section.description + '\n';
}

// Add the items for this section to the content
const itemsDir = path.join(__dirname, '../items');
const sectionDirs = fs.readdirSync(itemsDir);
let items = [];
for (const sectionDir of sectionDirs) {
const sectionDirPath = path.join(itemsDir, sectionDir);
if (fs.statSync(sectionDirPath).isDirectory()) {
const itemFiles = fs.readdirSync(sectionDirPath);
for (const itemFile of itemFiles) {
const itemFilePath = path.join(sectionDirPath, itemFile);
const itemFileContent = fs.readFileSync(itemFilePath, 'utf-8');
const item = matter(itemFileContent).data;

// Check if the item's section matches the current section
if (item.section === section.name) {
// Check if the item's category is valid or if it doesn't have a category
if (!item.category || categories.find(category => category.name === item.category)) {
items.push(item);
}
}
}
}
}

// Group the items by category if the section is Tools
const itemsByCategory = items.reduce((groups, item) => {
if (item.category) {
if (!groups[item.category]) {
groups[item.category] = [];
}
groups[item.category].push(item);
}
return groups;
}, {});

// Add the items to the content
if (section.name === 'Tools') {
for (const category of categories) {
content += '### ' + category.name + '\n';
if (category.description) {
// Uncomment this line to add the category description to the content
//content += category.description + '\n';
}
if (itemsByCategory[category.name]) {
itemsByCategory[category.name].sort((a, b) => {
if (a.order && b.order) {
return a.order - b.order;
} else {
return a.name.localeCompare(b.name);
}
});
for (const item of itemsByCategory[category.name]) {
content += '- [' + item.name + '](' + item.link + ') - ' + item.description + '\n';
}
}
content += '\n';
}
} else {

// Sort the items by order if it exists, otherwise by name
items.sort((a, b) => {
if (a.order && b.order) {
return a.order - b.order;
} else {
return a.name.localeCompare(b.name);
}
});

// Add the items to the content
for (const item of items) {
content += '- [' + item.name + '](' + item.link + ') - ' + item.description + '\n';
}

content += '\n';

}

}

// Add the contribution section
const contributePath = path.join(__dirname, '../partials/contribute.md');
const contributeContent = fs.readFileSync(contributePath, 'utf-8');
content += contributeContent;

// Write the combined content to the README file
fs.writeFileSync(path.join(__dirname, '../README.md'), content);
88 changes: 87 additions & 1 deletion .website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .website/package.json
CamKem marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview"
"preview": "nuxt preview",
"build-readme": "node build-readme.cjs"
},
"dependencies": {
"@nuxt/content": "^2.12.1",
"@nuxtjs/tailwindcss": "^6.11.4",
"@tailwindcss/typography": "^0.5.10",
"gray-matter": "^4.0.3",
"nuxt": "^3.10.3"
},
"devDependencies": {
Expand Down
Loading