Skip to content

Commit 5fc0890

Browse files
authored
fix: relative paths (#15)
* fix: use filename to get the dirname * refactor: update build
1 parent 16184e0 commit 5fc0890

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

build/blogpub.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Github = ReturnType<typeof getOctokit>;
1414

1515
async function loadArticleFile(
1616
github: Github, folderName: string,
17-
): Promise<{ rawUrl: string, content: string}> {
17+
): Promise<{ fileName: string, content: string}> {
1818
const { owner, repo } = context.repo;
1919
// NOTE: Pagination returns 30 files by default
2020
const commit = (
@@ -34,7 +34,7 @@ async function loadArticleFile(
3434
const newArticle = mdFiles[0];
3535
core.debug(`Using ${newArticle.filename!}`);
3636
const content = await fs.readFile(`./${newArticle.filename!}`, 'utf8');
37-
return { rawUrl: newArticle.raw_url!, content };
37+
return { fileName: newArticle.filename!, content };
3838
}
3939

4040
export async function run() {
@@ -49,7 +49,12 @@ export async function run() {
4949
const github = getOctokit(ghToken);
5050

5151
const articleFile = await loadArticleFile(github, articlesFolder);
52-
const baseUrl = path.dirname(articleFile.rawUrl);
52+
const rawGithubUrl = context.serverUrl
53+
.replace('//github.com', '//raw.githubusercontent.com');
54+
const { repo, owner } = context.repo;
55+
const branchName = context.ref.replace('refs/heads/', '');
56+
const fileUrl = `${rawGithubUrl}/${owner}/${repo}/${branchName}/${articleFile.fileName}`;
57+
const baseUrl = path.dirname(fileUrl);
5358
/* istanbul ignore next */
5459
core.debug(`Base URL: ${baseUrl}`);
5560
const article = parseArticle(articleFile.content, `${baseUrl}/`);

test/main.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jest.mock('$/api/devto');
2424
jest.mock('$/parser');
2525
jest.mock('@actions/github', () => ({
2626
context: {
27+
serverUrl: 'https://github.com',
28+
ref: 'refs/heads/main',
2729
repo: {
2830
owner: 'owner',
2931
repo: 'repo',
@@ -44,7 +46,6 @@ describe('blogpub', () => {
4446
files: [
4547
{
4648
filename: 'blogs/blog-01.md',
47-
raw_url: 'https://raw.githubusercontent.com/owner/repo/main/blogs/blog-01.md',
4849
},
4950
],
5051
},

0 commit comments

Comments
 (0)