Skip to content

Commit af998d1

Browse files
authored
refactor: improve relative paths matching (#22)
* refactor: remove cover_image as Dev.to API does not support it * refactor: improve relative path regex matching
1 parent 15b160e commit af998d1

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/api/devto.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export async function createArticle(
1111
const payload = {
1212
article: {
1313
body_markdown: content,
14-
cover_image: config.cover_image,
1514
description: config.description,
1615
published: config.published,
1716
title: config.title,

src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { load as loadYaml } from 'js-yaml';
33

44
import { Article, ArticleConfig, MediumLicense } from './types';
55

6-
const RelativePathRegex = /([\.]{1,2}\/.*)/;
6+
const RelativePathRegex = /[\('"]([\.]{1,2}\/\S*)[\)'"]/;
77

88
function getMetadataIndexes(lines: string[]): number[] {
99
const indexes: number[] = [];

src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export enum MediumLicense {
1111
}
1212

1313
export interface ArticleConfig {
14-
cover_image?: string;
1514
description?: string;
1615
license?: MediumLicense;
1716
published?: boolean;

test/parser.spec.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ some content`;
6969
some content`);
7070
});
7171

72-
7372
it('should parse all images with relative path', () => {
7473
const article = `
7574
---
7675
title: Some Title
77-
cover_image: ./cover.jpg
7876
description: New Article
7977
tags:
8078
- one
@@ -89,23 +87,32 @@ some content
8987
![img](../global/img.png)
9088
9189
<img alt="image" src="./assets/img.gif" />
90+
<video src='./assets/video.mp4' />
9291
9392
## Description
9493
`;
9594
const parsed = parseArticle(article, 'raw.github.com/protiumx/blogpub/main/articles/');
96-
expect(parsed.config.cover_image).toEqual('https://raw.github.com/protiumx/blogpub/main/articles/cover.jpg');
95+
9796
expect(parsed.config.tags).toEqual(['one', 'images']);
9897
expect(
9998
parsed.content.includes(
10099
'![img](https://raw.github.com/protiumx/blogpub/main/articles/assets/img.png)',
101-
)).toBeTruthy();
100+
),
101+
).toBeTruthy();
102102
expect(
103103
parsed.content.includes(
104104
'![img](https://raw.github.com/protiumx/blogpub/main/global/img.png)',
105-
)).toBeTruthy();
105+
),
106+
).toBeTruthy();
106107
expect(
107108
parsed.content.includes(
108109
'<img alt="image" src="https://raw.github.com/protiumx/blogpub/main/articles/assets/img.gif"',
109-
)).toBeTruthy();
110+
),
111+
).toBeTruthy();
112+
expect(
113+
parsed.content.includes(
114+
"<video src='https://raw.github.com/protiumx/blogpub/main/articles/assets/video.mp4'",
115+
),
116+
).toBeTruthy();
110117
});
111118
});

0 commit comments

Comments
 (0)