Skip to content

Commit 8b086f3

Browse files
committed
foo
1 parent 4af4ee0 commit 8b086f3

File tree

4 files changed

+9
-46
lines changed

4 files changed

+9
-46
lines changed

build/blog.service.ts

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import axios from 'axios';
21
import * as emoji from 'node-emoji'
32
import { JekyllMarkdownParser } from './jekyll-markdown-parser';
43
import { readdir, readFile } from 'fs/promises';
@@ -7,21 +6,9 @@ import { BlogEntry } from './types';
76

87
export class BlogService {
98

10-
private blogListFetched = this.getBlogListFromAPI();
9+
constructor(private markdownBaseUrl: string) {}
1110

12-
constructor(private settings: {
13-
headers: {
14-
'User-Agent': string,
15-
'Authorization': string
16-
},
17-
contentsRepo: string,
18-
branch: string,
19-
markdownBaseUrl: string
20-
}) {}
2111

22-
getBlogList() {
23-
return this.blogListFetched;
24-
}
2512

2613
async getBlogEntry(slug: string): Promise<BlogEntry> {
2714
const blogList = await this.getBlogList();
@@ -53,29 +40,26 @@ export class BlogService {
5340
return readFile(path, 'utf8');
5441
}
5542

56-
private async getBlogListFromAPI() {
43+
async getBlogList() {
5744
const blogDirs = await this.readBlogFolders();
5845
const blogEntries: BlogEntry[] = [];
5946

6047
for (const blogDir of blogDirs) {
61-
6248
try {
6349
const readme = await this.readBlogFileFromFolder(blogDir);
6450
const blogEntry = this.readmeToBlogEntry(readme, blogDir);
6551
blogEntries.push(blogEntry);
6652

6753
} catch (e: any) {
6854
const errorBlogEntry = {
69-
slug: this.slugifyPath(blogDir),
70-
html_url: '',
55+
slug: blogDir,
7156
error: e.message || 'Error',
7257
meta: {
7358
title: 'A minor error occurred while reading: ' + blogDir,
7459
hidden: true
7560
}
7661
} as BlogEntry;
7762
blogEntries.push(errorBlogEntry);
78-
7963
}
8064
}
8165

@@ -84,36 +68,23 @@ export class BlogService {
8468

8569

8670
private readmeToBlogEntry(readme: string, folder: string) {
87-
const parser = new JekyllMarkdownParser(this.settings.markdownBaseUrl + folder);
71+
const parser = new JekyllMarkdownParser(this.markdownBaseUrl + folder);
8872
const parsedJekyllMarkdown = parser.parse(readme);
8973

9074
const meta = parsedJekyllMarkdown.parsedYaml || {};
9175

9276
if (meta.thumbnail &&
9377
!meta.thumbnail.startsWith('http') &&
9478
!meta.thumbnail.startsWith('//')) {
95-
meta.thumbnail
96-
= this.settings.markdownBaseUrl + folder + meta.thumbnail;
79+
meta.thumbnail = this.markdownBaseUrl + folder + '/' + meta.thumbnail;
9780
}
9881

9982
return {
100-
slug: this.slugifyPath(folder),
83+
slug: folder,
10184
html: emoji.emojify(parsedJekyllMarkdown.html),
10285
meta: meta
10386
} as BlogEntry;
10487
}
105-
106-
private slugifyPath(path: string): string {
107-
if (!path) {
108-
return 'error - no path??';
109-
}
110-
111-
return path
112-
.replace(/README\.md$/, '')
113-
.replace('blog/', '')
114-
.replace(/\/$/, '')
115-
.replace('/', '|');
116-
}
11788
}
11889

11990

build/config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
export const githubConfig = {
2-
headers: {
3-
'User-Agent': 'No1 Fancy AngularSchule Request Handler',
4-
Authorization: 'token ba1ad58d9eb880fbd128abddb0df8ffae47cd407',
5-
},
6-
org: 'angular-schule',
7-
contentsRepo: 'website-articles',
8-
branch: 'gh-pages',
1+
export const config = {
92
markdownBaseUrl: 'https://angular-schule.github.io/website-articles/',
103
};

build/fetch-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { githubConfig } from './config';
1+
import { config } from './config';
22
import { BlogService } from './blog.service';
33
import { writeJSON, makeLightBlogList, createFolderIfNotExists } from './utils';
44

55
(async () => {
6-
const blogService = new BlogService(githubConfig);
6+
const blogService = new BlogService(config.markdownBaseUrl);
77

88
await createFolderIfNotExists('./dist/posts');
99

build/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export interface BlogEntryMeta {
2424

2525
export interface BlogEntry {
2626
slug: string; // SEO-friendly path
27-
html_url: string; // preview url on github
2827
html: string;
2928
error: string;
3029
meta: BlogEntryMeta;

0 commit comments

Comments
 (0)