Skip to content

Commit 134545e

Browse files
committed
refactor: organize code into blog/, material/, shared/ folders
- Move blog-specific files to blog/ - Move material-specific files to material/ - Move shared utilities to shared/ - Delete obsolete build-blog.ts and build-material.ts - Add types.d.ts for marked-gfm-heading-id - Update imports and README - Fix package.json name and remove unused main field - Remove dead code (parsedYaml ?? {}) - Remove error field from MaterialEntry (website-only)
1 parent a26151e commit 134545e

19 files changed

Lines changed: 121 additions & 168 deletions

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ jobs:
2121
- name: Install dependencies
2222
run: npm ci
2323

24+
- name: Typecheck
25+
run: npm run typecheck
26+
2427
- name: Run tests
2528
run: npm test

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Shared build scripts for processing Markdown blog entries into JSON.
44

5-
Used as a git submodule in:
5+
Used as a git subtree in:
66
- [angular-buch/website-articles](https://github.com/angular-buch/website-articles)
77
- [angular-schule/website-articles](https://github.com/angular-schule/website-articles)
88

@@ -13,15 +13,31 @@ npm install
1313
npm run build
1414
```
1515

16-
## Build Scripts
16+
## Scripts
1717

18-
| Script | Description |
19-
|------------------|------------------------------------------------------------------|
20-
| `build:init` | Clears `dist/` |
21-
| `build:blog` | Builds blog entries from `../blog/``dist/blog/` |
22-
| `build:material` | Builds material entries from `../material/``dist/material/` |
18+
| Script | Description |
19+
|--------------|--------------------------------------|
20+
| `build` | Build blog and material entries |
21+
| `test` | Run tests |
22+
| `test:watch` | Run tests in watch mode |
23+
| `typecheck` | TypeScript type checking |
24+
| `watch` | Watch mode for development |
2325

24-
**Note:** `build:material` gracefully exits if no `../material/` folder exists.
26+
## Folder Structure
27+
28+
```
29+
├── build.ts # Main entry point
30+
├── blog/
31+
│ ├── blog.types.ts # Blog-specific types
32+
│ └── blog.utils.ts # Blog list utilities
33+
├── material/
34+
│ └── material.types.ts # Material-specific types
35+
└── shared/
36+
├── base.types.ts # Shared base types
37+
├── base.utils.ts # File/folder utilities
38+
├── list.utils.ts # List extraction utilities
39+
└── jekyll-markdown-parser.ts # Markdown parser
40+
```
2541

2642
## URL Placeholder
2743

@@ -31,8 +47,12 @@ Generated URLs use `%%MARKDOWN_BASE_URL%%` as a placeholder:
3147

3248
The consuming website replaces this placeholder with the actual base URL at runtime.
3349

34-
## Tests
50+
## Input/Output
3551

36-
```bash
37-
npm test
38-
```
52+
**Input:** `../blog/` and `../material/` folders with Markdown READMEs
53+
54+
**Output:** `./dist/` folder with:
55+
- `dist/blog/list.json` - Light blog list for overview
56+
- `dist/blog/{slug}/entry.json` - Full blog entry
57+
- `dist/material/list.json` - Light material list
58+
- `dist/material/{slug}/entry.json` - Full material entry

blog.types.ts renamed to blog/blog.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageDimensions } from "./base.types";
1+
import { ImageDimensions } from "../shared/base.types";
22

33
/**
44
* Blog entry metadata for the LIGHT list (list.json).
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ describe('makeLightBlogList', () => {
1515
published: '2024-01-01T00:00:00.000Z',
1616
language: 'en',
1717
header: { url: 'header.jpg', width: 800, height: 400 },
18-
'darken-header': false,
18+
hidden: false,
19+
sticky: false,
20+
darkenHeader: false,
1921
...overrides.meta,
2022
},
2123
...overrides,
@@ -68,7 +70,7 @@ describe('makeLightBlogList', () => {
6870
language: 'de',
6971
header: { url: 'img.jpg', width: 100, height: 50 },
7072
hidden: false,
71-
'darken-header': true,
73+
darkenHeader: true,
7274
keywords: ['angular', 'test'],
7375
bio: 'Some bio',
7476
sticky: true,
@@ -88,11 +90,11 @@ describe('makeLightBlogList', () => {
8890
expect(meta.header).toEqual({ url: 'img.jpg', width: 100, height: 50 });
8991

9092
// These should NOT be included in light version
91-
expect((meta as any).hidden).toBeUndefined();
92-
expect((meta as any)['darken-header']).toBeUndefined();
93-
expect((meta as any).keywords).toBeUndefined();
94-
expect((meta as any).bio).toBeUndefined();
95-
expect((meta as any).sticky).toBeUndefined();
93+
expect(Object.hasOwn(meta, 'hidden')).toBe(false);
94+
expect(Object.hasOwn(meta, 'darkenHeader')).toBe(false);
95+
expect(Object.hasOwn(meta, 'keywords')).toBe(false);
96+
expect(Object.hasOwn(meta, 'bio')).toBe(false);
97+
expect(Object.hasOwn(meta, 'sticky')).toBe(false);
9698
});
9799

98100
it('should include author2 and mail2 if present', () => {

blog.utils.ts renamed to blog/blog.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BlogEntry, BlogEntryFull } from './blog.types';
2-
import { extractFirstBigParagraph } from './list.utils';
2+
import { extractFirstBigParagraph } from '../shared/list.utils';
33

44
export function makeLightBlogList(fullList: BlogEntryFull[]): BlogEntry[] {
55
return fullList

build-blog.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

build-material.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

build.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { existsSync } from 'fs';
22
import * as path from 'path';
33
import { mkdirp, remove, writeJson } from 'fs-extra';
44

5-
import { BlogEntryFull } from './blog.types';
6-
import { MaterialEntry } from './material.types';
7-
import { copyEntriesToDist, getEntryList } from './base.utils';
8-
import { makeLightBlogList } from './blog.utils';
9-
import { makeLightList } from './list.utils';
10-
import { MARKDOWN_BASE_URL_PLACEHOLDER } from './jekyll-markdown-parser';
5+
import { BlogEntryFull } from './blog/blog.types';
6+
import { MaterialEntry } from './material/material.types';
7+
import { copyEntriesToDist, getEntryList } from './shared/base.utils';
8+
import { makeLightBlogList } from './blog/blog.utils';
9+
import { makeLightList } from './shared/list.utils';
10+
import { MARKDOWN_BASE_URL_PLACEHOLDER } from './shared/jekyll-markdown-parser';
1111

1212
const DIST_FOLDER = './dist';
1313
const BLOG_FOLDER = '../blog';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EntryBase, EntryMetaBase } from "./base.types";
1+
import { EntryBase, EntryMetaBase } from "../shared/base.types";
22

33
/**
44
* Material entry metadata.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"name": "website-articles",
2+
"name": "website-articles-build",
33
"version": "1.0.0",
4-
"main": "index.js",
54
"scripts": {
65
"build": "tsx build.ts",
76
"watch": "nodemon --watch ../blog --watch ../material -e md,jpg,png,svg --exec 'npm run build'",

0 commit comments

Comments
 (0)