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/content.ts | |
parent | 92eccbf4f6784fbee7505996a97aa5bb27d12238 (diff) |
feat: Client lib now supports path prefix
Diffstat (limited to 'lib/client/src/content.ts')
-rw-r--r-- | lib/client/src/content.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/client/src/content.ts b/lib/client/src/content.ts index c1a62aa..9626c65 100644 --- a/lib/client/src/content.ts +++ b/lib/client/src/content.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 @@ -13,7 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -import { startsWith } from 'lodash-es'; +import { defaultTo, startsWith } from 'lodash-es'; import { CMNextApi, CMNextAutoConfig, CMNextEntity, CMNextIndex, ContentMeta } from "./types"; import { createScopedChannelApi } from "./channels"; @@ -88,9 +88,11 @@ export const createManualContentApi = ({ channelRootDir, contentIndexPath, conte * @param param0 The CMNext configuration for the auto content api * @returns The automatic discovery content api */ -export const createAutoContentApi = ({ cmsChannelIndexPath, channelId }: CMNextAutoConfig): ContentApi => { +export const createAutoContentApi = ({ cmsChannelIndexPath, channelId, urlPrefix }: CMNextAutoConfig): ContentApi => { - const channelApi = createScopedChannelApi(cmsChannelIndexPath, channelId); + urlPrefix = defaultTo(urlPrefix, ''); + + const channelApi = createScopedChannelApi(cmsChannelIndexPath, channelId, urlPrefix); const getIndex = async () : Promise<CMNextIndex<ContentMeta>> => { //Get the content index path from the channel api @@ -106,7 +108,8 @@ export const createAutoContentApi = ({ cmsChannelIndexPath, channelId }: CMNextA const getContentUrl = async (item: ContentMeta): Promise<string> => { //Content resides in the content dir within the channel dir const contentDir = await channelApi.getContentDir(); - return contentDir ? `${contentDir}/${item.path}` : '' + const baseDir = await channelApi.getBaseDir(); + return contentDir ? `${urlPrefix}${baseDir}/${contentDir}/${item.path}` : '' } const getStringContent = async (item: ContentMeta): Promise<string> => { |