diff options
author | vnugent <public@vaughnnugent.com> | 2024-03-15 17:00:41 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-03-15 17:00:41 -0400 |
commit | f9e2109c27af5ece546261c018d4b2781860ff1c (patch) | |
tree | 8b9362c873ce4ef5a98205499f829271fc9f8af9 /lib/client/src/posts.ts | |
parent | 92eccbf4f6784fbee7505996a97aa5bb27d12238 (diff) |
feat: Client lib now supports path prefix
Diffstat (limited to 'lib/client/src/posts.ts')
-rw-r--r-- | lib/client/src/posts.ts | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/client/src/posts.ts b/lib/client/src/posts.ts index d2c8791..63819a1 100644 --- a/lib/client/src/posts.ts +++ b/lib/client/src/posts.ts @@ -1,4 +1,4 @@ -// Copyright (C) 2023 Vaughn Nugent +// Copyright (C) 2024 Vaughn Nugent // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -71,9 +71,9 @@ export interface PostApiManualConfig { * @param channelId The id of the channel to get posts from * @returns A post api that can be used to get posts from the channel */ -export const createAutoPostApi = ({ cmsChannelIndexPath, channelId }: CMNextAutoConfig): AutoPostApi => { +export const createAutoPostApi = ({ cmsChannelIndexPath, channelId, urlPrefix }: CMNextAutoConfig): AutoPostApi => { //Use scoped channel api - const channelApi = createScopedChannelApi(cmsChannelIndexPath, channelId); + const channelApi = createScopedChannelApi(cmsChannelIndexPath, channelId, urlPrefix); const getIndex = async (): Promise<CMNextIndex<PostMeta>> => { //Await the selected channel index @@ -99,16 +99,16 @@ export const createAutoPostApi = ({ cmsChannelIndexPath, channelId }: CMNextAuto return "" } - const itemId = defaultTo(post.id, post) + const itemId = defaultTo((post as PostMeta).id, post) //Fetch the content as text because it is html - const res = await fetch(`${baseDir}${contentDir}/${itemId}${extension}`) + const res = await fetch(`${urlPrefix}${baseDir}${contentDir}/${itemId}${extension}`) return await res.text() } const getIndexFilePath = async () : Promise<string> => { const indexUrl = await channelApi.getPostIndexPath(); - return indexUrl || "" + return defaultTo(indexUrl, "") } return{ @@ -147,7 +147,7 @@ export const createManualPostApi = ({ channelRootDir, contentDir, postIndexPath const getPostContent = async (post: PostMeta | string, extension = '.html'): Promise<string> => { //Get the content url - const contentUrl = `${getItemPath(contentDir)}/${defaultTo(post.id, post)}${extension}` + const contentUrl = `${getItemPath(contentDir)}/${defaultTo((post as PostMeta).id, post)}${extension}` //Fetch the content as text because it is html const res = await fetch(contentUrl) |