Skip to content

Commit d553f83

Browse files
committed
Added markdownlint, Added some posts
Markdown lint check can be run by `npm run lint` and will be run automatically by github workflows
1 parent cbf55b3 commit d553f83

14 files changed

+918
-2
lines changed

.github/workflows/lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Lint Markdown Files
2+
3+
# Run this job on all pushes and pull requests
4+
on:
5+
push:
6+
branches:
7+
- "*"
8+
pull_request: {}
9+
10+
jobs:
11+
# Perform the lint
12+
lint:
13+
if: contains(github.event.head_commit.message, '[skip ci]') == false
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
21+
- name: Use Node.js 20
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: 20
25+
26+
- name: Install Dependencies
27+
run: npm ci
28+
29+
- name: Lint
30+
run: npm run lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.markdownlint.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"default": true,
3+
4+
"MD013": false,
5+
6+
"MD024": {
7+
"siblings_only": true
8+
},
9+
10+
"MD033": {
11+
"allowed_elements": [
12+
"br",
13+
"details",
14+
"summary",
15+
"svgicon"
16+
]
17+
}
18+
}

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,21 @@ Alternativ kann auch `<svgicon ... />` verwendet werden, wodurch das Icon beispi
347347
<svgicon github>
348348
```
349349

350+
## Prüfung der Markdown-Dateien
351+
352+
Die Markdown-Dateien können mittels [markdownlint](https://github.com/DavidAnson/markdownlint) automatisch überprüft werden.
353+
354+
Hierzu müssen zuerst die Node.js-Module installiert werden.
355+
Anschließend kann das `lint`-Script aufgerufen werden.
356+
357+
```sh
358+
npm install
359+
npm run lint
360+
```
361+
362+
Erkannte Probleme in Dateien im `drafts`-Verzeichnis werden als Warnung angezeigt.
363+
Probleme in Dateien im `posts`-Verzeichnis werden als Fehler angezeigt und das Script mit Exit-Code 1 beendet.
364+
350365
## Lizenz
351366

352367
[CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/), sofern nicht abweichend in den Beiträgen angegeben.

lint.mjs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This script runs markdownlint for all md filed in `posts` and `drafts` dirs.
3+
*
4+
* All errors will be logged.
5+
*
6+
* Any error found in `posts` files will result in non-zero exit code.
7+
* Errors found `drafts` files will just be logged.
8+
*/
9+
10+
import { globSync } from 'glob';
11+
import markdownlint from 'markdownlint';
12+
13+
const config = markdownlint.readConfigSync('.markdownlint.json');
14+
15+
const files = globSync([
16+
'posts/*.md',
17+
'drafts/*.md',
18+
]);
19+
20+
/** @type {markdownlint.Options} */
21+
const options = {
22+
config,
23+
files,
24+
};
25+
26+
console.log('Linting markdown files in posts and drafts ...\n');
27+
28+
const results = markdownlint.sync(options);
29+
30+
let postsErrorCount = 0;
31+
let draftsErrorCount = 0;
32+
33+
for (const fileName in results) {
34+
const result = results[fileName];
35+
if (result.length === 0) {
36+
// no errors
37+
console.log(`✔️ ${fileName} - ok`);
38+
continue;
39+
}
40+
41+
// there were some errors... count and log them
42+
for (const err of result) {
43+
const isDraft = fileName.startsWith('drafts/');
44+
let symbol = '❌';
45+
if (isDraft) {
46+
draftsErrorCount++;
47+
symbol = '🚧';
48+
} else {
49+
postsErrorCount++;
50+
}
51+
52+
console.log(`${symbol} ${fileName}:${err.lineNumber} - ${err.ruleNames.join('/')} ${err.ruleDescription} [${err.errorDetail}]`);
53+
}
54+
}
55+
56+
console.log('\n──────────');
57+
58+
if (postsErrorCount === 0 && draftsErrorCount === 0) {
59+
console.log('All fine. 👍️');
60+
} else {
61+
if (postsErrorCount > 0) {
62+
console.log(`❌ ${postsErrorCount} error${postsErrorCount > 1 ? 's' : ''} found in posts`);
63+
}
64+
if (draftsErrorCount > 0) {
65+
console.log(`🚧 ${draftsErrorCount} error${draftsErrorCount > 1 ? 's' : ''} found in drafts`);
66+
}
67+
}
68+
69+
console.log('──────────');
70+
71+
if (postsErrorCount > 0) {
72+
process.exitCode = 1;
73+
}

0 commit comments

Comments
 (0)