Skip to content

Commit d270606

Browse files
committed
feat: add list patterns dynamic in README file
1 parent 1ac7bfe commit d270606

File tree

4 files changed

+182
-17
lines changed

4 files changed

+182
-17
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Update Patterns List
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- "content/en/patterns/**"
10+
11+
jobs:
12+
update-readme:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: "20"
24+
25+
- name: Update README
26+
run: node scripts/update-patterns-list.js
27+
28+
- name: Commit changes
29+
run: |
30+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
31+
git config --local user.name "github-actions[bot]"
32+
git add README.md
33+
git diff --quiet && git diff --staged --quiet || git commit -m "docs: update patterns list [skip ci]"
34+
git push

README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,67 @@ UX Patterns for Developers is a free collection of UX patterns towards developer
99
1010
## 🧩 Patterns
1111

12-
This is an non-exhaustive list of available and incoming patterns.
12+
<!-- PATTERNS-LIST:START - Do not remove or modify this section -->
1313

14-
### Navigation
14+
This is an updated list of available and incoming patterns.
1515

16-
- [Breadcrumbs](https://uxpatterns.dev/en/patterns/navigation/breadcrumb)
17-
- Navigation Menu (coming soon)
18-
- Pagination (coming soon)
16+
### Content Management
17+
18+
- Accordion (coming soon)
19+
- Carousel (coming soon)
20+
- Drag And Drop (coming soon)
21+
- Modal (coming soon)
22+
- Tooltip (coming soon)
1923

20-
### Input & Forms
24+
### Forms
2125

22-
- [Button](https://uxpatterns.dev/en/patterns/forms/button)
26+
- [Autocomplete](https://uxpatterns.dev/patterns/forms/autocomplete)
27+
- [Button](https://uxpatterns.dev/patterns/forms/button)
2328
- Checkbox (coming soon)
2429
- Code Confirmation (coming soon)
2530
- Color Picker (coming soon)
2631
- Currency Input (coming soon)
2732
- Date Input (coming soon)
2833
- Date Picker (coming soon)
2934
- Date Range (coming soon)
35+
- [Dropdown](https://uxpatterns.dev/patterns/forms/dropdown)
3036
- File Input (coming soon)
3137
- Form Validation (coming soon)
32-
- Multi-select Input (coming soon)
38+
- Multi Select Input (coming soon)
3339
- Password (coming soon)
3440
- Phone Number (coming soon)
3541
- Radio (coming soon)
36-
- Search Input (coming soon)
42+
- Rating Input (coming soon)
43+
- Rich Text Editor (coming soon)
44+
- Search Field (coming soon)
3745
- Selection Input (coming soon)
46+
- Signature Pad (coming soon)
3847
- Slider (coming soon)
48+
- Tag Input (coming soon)
3949
- Text Field (coming soon)
4050
- Time Input (coming soon)
4151
- Toggle (coming soon)
4252

43-
### Content Management
53+
### Navigation
4454

45-
- Accordion (coming soon)
46-
- Carousel (coming soon)
47-
- Drag and Drop (coming soon)
48-
- Modal (coming soon)
49-
- Tooltip (coming soon)
55+
- [Back To Top](https://uxpatterns.dev/patterns/navigation/back-to-top)
56+
- [Breadcrumb](https://uxpatterns.dev/patterns/navigation/breadcrumb)
57+
- Hambuger Menu (coming soon)
58+
- Megamenu (coming soon)
59+
- Navigation Menu (coming soon)
60+
- Pagination (coming soon)
61+
- Sidebar (coming soon)
62+
- Tabs (coming soon)
5063

5164
### User Feedback
5265

66+
- Cookie Consent (coming soon)
5367
- Empty States (coming soon)
5468
- Loading Indicator (coming soon)
55-
- Notifications (coming soon)
69+
- Notification (coming soon)
5670
- Progress Indicator (coming soon)
71+
- Skeleton (coming soon)
72+
<!-- PATTERNS-LIST:END -->
5773

5874
## Getting Started
5975

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"release:verbose": "auto shipit -v",
2121
"release:version": "auto version -v",
2222
"start": "next start",
23-
"tsc": "tsc --noEmit"
23+
"tsc": "tsc --noEmit",
24+
"update-patterns": "node scripts/update-patterns-list.js"
2425
},
2526
"packageManager": "[email protected]",
2627
"browserslist": [

scripts/update-patterns-list.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = path.dirname(__filename);
7+
8+
const PATTERNS_DIR = path.join(path.dirname(__dirname), "content/en/patterns");
9+
const README_PATH = path.join(path.dirname(__dirname), "README.md");
10+
const PROD_URL = "https://uxpatterns.dev/patterns";
11+
12+
// Markers for the patterns section in README
13+
const START_MARKER =
14+
"<!-- PATTERNS-LIST:START - Do not remove or modify this section -->";
15+
const END_MARKER = "<!-- PATTERNS-LIST:END -->";
16+
17+
// Helper to check if a pattern is complete by checking its content
18+
function isPatternComplete(filePath) {
19+
try {
20+
const content = fs.readFileSync(filePath, "utf8");
21+
// A pattern is considered complete if it has more than 50 lines
22+
// You might want to adjust this threshold or use a different criteria
23+
return content.split("\n").length > 50;
24+
} catch (error) {
25+
return false;
26+
}
27+
}
28+
29+
// Convert string to title case
30+
function toTitleCase(str) {
31+
return str
32+
.split("-")
33+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
34+
.join(" ");
35+
}
36+
37+
function generatePatternsList() {
38+
// Get all pattern categories (directories)
39+
const categories = fs
40+
.readdirSync(PATTERNS_DIR)
41+
.filter(
42+
(item) =>
43+
fs.statSync(path.join(PATTERNS_DIR, item)).isDirectory() &&
44+
!item.startsWith("_")
45+
);
46+
47+
// Generate patterns list
48+
let patternsContent =
49+
"\nThis is an updated list of available and incoming patterns.\n";
50+
51+
for (const category of categories) {
52+
const categoryPath = path.join(PATTERNS_DIR, category);
53+
const patterns = fs
54+
.readdirSync(categoryPath)
55+
.filter((file) => file.endsWith(".mdx") && !file.startsWith("_"))
56+
.map((file) => file.replace(".mdx", ""));
57+
58+
if (patterns.length > 0) {
59+
const categoryTitle = toTitleCase(category);
60+
patternsContent += `\n### ${categoryTitle}\n\n`;
61+
62+
for (const pattern of patterns) {
63+
const patternPath = path.join(categoryPath, `${pattern}.mdx`);
64+
const isComplete = isPatternComplete(patternPath);
65+
const patternTitle = toTitleCase(pattern);
66+
67+
if (isComplete) {
68+
patternsContent += `- [${patternTitle}](${PROD_URL}/${category}/${pattern})\n`;
69+
} else {
70+
patternsContent += `- ${patternTitle} (coming soon)\n`;
71+
}
72+
}
73+
}
74+
}
75+
76+
return patternsContent;
77+
}
78+
79+
function updatePatternsList() {
80+
try {
81+
// Read current README
82+
let readme = fs.readFileSync(README_PATH, "utf8");
83+
84+
// Check if markers exist
85+
if (!readme.includes(START_MARKER) || !readme.includes(END_MARKER)) {
86+
throw new Error(
87+
`Could not find ${START_MARKER} and ${END_MARKER} markers in README.md. Please add them around the patterns section.`
88+
);
89+
}
90+
91+
// Generate new patterns list
92+
const patternsContent = generatePatternsList();
93+
94+
// Replace content between markers
95+
const newReadme = readme.replace(
96+
new RegExp(`${START_MARKER}[\\s\\S]*?${END_MARKER}`),
97+
`${START_MARKER}${patternsContent}${END_MARKER}`
98+
);
99+
100+
// Write updated README
101+
fs.writeFileSync(README_PATH, newReadme);
102+
console.log("✅ README.md has been updated successfully!");
103+
} catch (error) {
104+
console.error("��� Error updating patterns list:", error);
105+
process.exit(1);
106+
}
107+
}
108+
109+
// Run the update if this file is being executed directly
110+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
111+
updatePatternsList();
112+
}
113+
114+
export default updatePatternsList;

0 commit comments

Comments
 (0)