From 03c527b0c5b41633cfff75dad5bcdf5bc97e967d Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Thu, 9 Nov 2023 09:09:14 -0500 Subject: [PATCH 1/3] fix absolute media urls leading slash being trimmed --- .../dev-test/backends/bitbucket/config.yml | 2 +- .../dev-test/backends/git-gateway/config.yml | 2 +- .../core/dev-test/backends/github/config.yml | 2 +- .../core/dev-test/backends/gitlab/config.yml | 2 +- .../core/dev-test/backends/gitlab/index.js | 21 ----------------- .../core/dev-test/backends/test/config.yml | 2 +- packages/core/dev-test/config.yml | 2 +- packages/core/dev-test/index.js | 23 ------------------- .../components/common/card/CardContent.tsx | 2 +- packages/core/src/lib/util/media.util.ts | 14 ++++------- packages/demo/public/editorial/config.yml | 2 +- packages/demo/public/simple/config.yml | 2 +- packages/demo/src/cms.js | 23 ------------------- 13 files changed, 14 insertions(+), 85 deletions(-) diff --git a/packages/core/dev-test/backends/bitbucket/config.yml b/packages/core/dev-test/backends/bitbucket/config.yml index cd011dc89..f3d78b188 100644 --- a/packages/core/dev-test/backends/bitbucket/config.yml +++ b/packages/core/dev-test/backends/bitbucket/config.yml @@ -3,7 +3,7 @@ backend: branch: main repo: staticcms/static-cms-bitbucket site_url: 'https://example.com' -media_folder: assets/uploads +media_folder: /assets/uploads media_library: folder_support: true locale: en diff --git a/packages/core/dev-test/backends/git-gateway/config.yml b/packages/core/dev-test/backends/git-gateway/config.yml index cfcf86358..50ebacc5b 100644 --- a/packages/core/dev-test/backends/git-gateway/config.yml +++ b/packages/core/dev-test/backends/git-gateway/config.yml @@ -2,7 +2,7 @@ backend: name: git-gateway branch: main site_url: 'https://example.com' -media_folder: assets/uploads +media_folder: /assets/uploads media_library: folder_support: true locale: en diff --git a/packages/core/dev-test/backends/github/config.yml b/packages/core/dev-test/backends/github/config.yml index 49cb7b9c9..e37032893 100644 --- a/packages/core/dev-test/backends/github/config.yml +++ b/packages/core/dev-test/backends/github/config.yml @@ -3,7 +3,7 @@ backend: branch: main repo: staticjscms/static-cms-github site_url: 'https://example.com' -media_folder: assets/uploads +media_folder: /assets/uploads media_library: folder_support: true locale: en diff --git a/packages/core/dev-test/backends/gitlab/config.yml b/packages/core/dev-test/backends/gitlab/config.yml index dc796af42..225f3fa93 100644 --- a/packages/core/dev-test/backends/gitlab/config.yml +++ b/packages/core/dev-test/backends/gitlab/config.yml @@ -5,7 +5,7 @@ backend: auth_type: pkce app_id: 589ccb30ce31da8ba08e0b1e10b681a10be108e144508c2712573c6e4d60707e site_url: 'https://example.com' -media_folder: assets/uploads +media_folder: /assets/uploads media_library: folder_support: true locale: en diff --git a/packages/core/dev-test/backends/gitlab/index.js b/packages/core/dev-test/backends/gitlab/index.js index 91160aa60..208219ed8 100644 --- a/packages/core/dev-test/backends/gitlab/index.js +++ b/packages/core/dev-test/backends/gitlab/index.js @@ -24,27 +24,6 @@ const PostDateFieldPreview = ({ value }) => { ); }; -const PostDraftFieldPreview = ({ value }) => { - return h( - 'div', - { - style: { - backgroundColor: value === true ? 'rgb(37 99 235)' : 'rgb(22 163 74)', - color: 'white', - border: 'none', - padding: '2px 6px', - textAlign: 'center', - textDecoration: 'none', - display: 'inline-block', - cursor: 'pointer', - borderRadius: '4px', - fontSize: '14px', - }, - }, - value === true ? 'Draft' : 'Published', - ); -}; - const GeneralPreview = ({ widgetsFor, entry, collection }) => { const title = entry.data.site_title; const posts = entry.data.posts; diff --git a/packages/core/dev-test/backends/test/config.yml b/packages/core/dev-test/backends/test/config.yml index 89e4b8a33..236f4f8d8 100644 --- a/packages/core/dev-test/backends/test/config.yml +++ b/packages/core/dev-test/backends/test/config.yml @@ -1,7 +1,7 @@ backend: name: test-repo site_url: 'https://example.com' -media_folder: assets/uploads +media_folder: /assets/uploads media_library: folder_support: true locale: en diff --git a/packages/core/dev-test/config.yml b/packages/core/dev-test/config.yml index 89e4b8a33..236f4f8d8 100644 --- a/packages/core/dev-test/config.yml +++ b/packages/core/dev-test/config.yml @@ -1,7 +1,7 @@ backend: name: test-repo site_url: 'https://example.com' -media_folder: assets/uploads +media_folder: /assets/uploads media_library: folder_support: true locale: en diff --git a/packages/core/dev-test/index.js b/packages/core/dev-test/index.js index 6c3bdf52b..a4f321b9f 100644 --- a/packages/core/dev-test/index.js +++ b/packages/core/dev-test/index.js @@ -24,29 +24,6 @@ const PostDateFieldPreview = ({ value }) => { ); }; -const PostDraftFieldPreview = ({ value }) => { - return h( - 'div', - { - style: { - backgroundColor: value === true ? 'rgb(37 99 235)' : 'rgb(22 163 74)', - color: 'white', - border: 'none', - padding: '2px 6px', - textAlign: 'center', - textDecoration: 'none', - display: 'inline-block', - cursor: 'pointer', - borderRadius: '4px', - fontSize: '14px', - lineHeight: '16px', - height: '20px', - }, - }, - value === true ? 'Draft' : 'Published', - ); -}; - const GeneralPreview = ({ widgetsFor, entry, collection }) => { const title = entry.data.site_title; const posts = entry.data.posts; diff --git a/packages/core/src/components/common/card/CardContent.tsx b/packages/core/src/components/common/card/CardContent.tsx index 6fa1d123c..ad1df1365 100644 --- a/packages/core/src/components/common/card/CardContent.tsx +++ b/packages/core/src/components/common/card/CardContent.tsx @@ -9,7 +9,7 @@ interface CardContentProps { } const CardContent: FC = ({ children }) => { - return

{children}

; + return
{children}
; }; export default CardContent; diff --git a/packages/core/src/lib/util/media.util.ts b/packages/core/src/lib/util/media.util.ts index d875432a0..609c38b3d 100644 --- a/packages/core/src/lib/util/media.util.ts +++ b/packages/core/src/lib/util/media.util.ts @@ -1,4 +1,3 @@ -import trim from 'lodash/trim'; import { dirname } from 'path'; import { basename, isAbsolutePath } from '.'; @@ -259,7 +258,7 @@ export function selectMediaFolder( } } - return trim(mediaFolder, '/'); + return mediaFolder; } export function selectMediaFilePublicPath( @@ -297,7 +296,7 @@ export function selectMediaFilePublicPath( const mediaFolder = customMediaFolder ? evaluateFolder('media_folder', config, collection!, entryMap, field) : config['media_folder']; - selectedPublicFolder = trim(currentFolder, '/').replace(trim(mediaFolder!, '/'), publicFolder); + selectedPublicFolder = currentFolder.replace(mediaFolder!, publicFolder); } const finalPublicPath = joinUrlPath(selectedPublicFolder, basename(mediaPath)); @@ -322,17 +321,14 @@ export function selectMediaFilePath( let mediaFolder = selectMediaFolder(config, collection, entryMap, field, currentFolder); if (!currentFolder) { - let publicFolder = trim(config['public_folder'] ?? mediaFolder, '/'); - let mediaPathDir = trim(dirname(mediaPath), '/'); + let publicFolder = config['public_folder'] ?? mediaFolder; + let mediaPathDir = dirname(mediaPath); if (mediaPathDir === '.') { mediaPathDir = ''; } if (hasCustomFolder('public_folder', collection, entryMap?.slug, field)) { - publicFolder = trim( - evaluateFolder('public_folder', config, collection!, entryMap, field), - '/', - ); + publicFolder = evaluateFolder('public_folder', config, collection!, entryMap, field); } if (mediaPathDir.includes(publicFolder) && mediaPathDir != mediaFolder) { diff --git a/packages/demo/public/editorial/config.yml b/packages/demo/public/editorial/config.yml index 45e2efcf9..39d4e1066 100644 --- a/packages/demo/public/editorial/config.yml +++ b/packages/demo/public/editorial/config.yml @@ -1,7 +1,7 @@ backend: name: test-repo site_url: 'https://example.com' -media_folder: assets/uploads +media_folder: /assets/uploads media_library: folder_support: true locale: en diff --git a/packages/demo/public/simple/config.yml b/packages/demo/public/simple/config.yml index e08d6b74f..235d52d55 100644 --- a/packages/demo/public/simple/config.yml +++ b/packages/demo/public/simple/config.yml @@ -1,7 +1,7 @@ backend: name: test-repo site_url: 'https://example.com' -media_folder: assets/uploads +media_folder: /assets/uploads media_library: folder_support: true locale: en diff --git a/packages/demo/src/cms.js b/packages/demo/src/cms.js index 0e4f01217..2afd87adb 100644 --- a/packages/demo/src/cms.js +++ b/packages/demo/src/cms.js @@ -30,29 +30,6 @@ const PostDateFieldPreview = ({ value }) => { ); }; -const PostDraftFieldPreview = ({ value }) => { - return h( - 'div', - { - style: { - backgroundColor: value === true ? 'rgb(37 99 235)' : 'rgb(22 163 74)', - color: 'white', - border: 'none', - padding: '2px 6px', - textAlign: 'center', - textDecoration: 'none', - display: 'inline-block', - cursor: 'pointer', - borderRadius: '4px', - fontSize: '14px', - lineHeight: '16px', - height: '20px', - }, - }, - value === true ? 'Draft' : 'Published', - ); -}; - const GeneralPreview = ({ widgetsFor, entry, collection }) => { const title = entry.data.site_title; const posts = entry.data.posts; From d288a33fdc39687ce08583398f2e5d3d168959e3 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Thu, 9 Nov 2023 09:10:41 -0500 Subject: [PATCH 2/3] Update cypress.config.ts --- cypress.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress.config.ts b/cypress.config.ts index 9e40f7d28..e10666574 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -4,7 +4,7 @@ import setupNodeEvents from "./cypress/plugins"; export default defineConfig({ projectId: "wvw3x3", retries: { - runMode: 0, + runMode: 2, openMode: 0, }, chromeWebSecurity: false, From 478cec4735055edceaae0fb3e15e199b93327fd8 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Thu, 9 Nov 2023 11:15:53 -0500 Subject: [PATCH 3/3] WIP --- .../core/src/lib/util/__tests__/media.util.spec.ts | 10 +++++----- packages/core/src/lib/util/media.util.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/src/lib/util/__tests__/media.util.spec.ts b/packages/core/src/lib/util/__tests__/media.util.spec.ts index 174a38d56..ff71de180 100644 --- a/packages/core/src/lib/util/__tests__/media.util.spec.ts +++ b/packages/core/src/lib/util/__tests__/media.util.spec.ts @@ -245,7 +245,7 @@ describe('media.util', () => { .fields[3] as FileOrImageField; expect(selectMediaFolder(mockConfig, mockCollection, mockBaseEntry, mockImageField)).toBe( - 'path/to/some/other/media/folder', + '/path/to/some/other/media/folder', ); }); @@ -273,7 +273,7 @@ describe('media.util', () => { expect( selectMediaFolder(mockConfig, mockCollection, mockBaseEntry, mockImageField), - ).toBe('path/to/some/other/media/i-am-a-title'); + ).toBe('/path/to/some/other/media/i-am-a-title'); }); it('should substitute slug', () => { @@ -309,7 +309,7 @@ describe('media.util', () => { }); expect(selectMediaFolder(mockConfig, mockCollection, mockEntry, mockImageField)).toBe( - 'path/to/some/other/media/i-am-a-title-fish', + '/path/to/some/other/media/i-am-a-title-fish', ); }); @@ -345,7 +345,7 @@ describe('media.util', () => { }); expect(selectMediaFolder(mockConfig, mockCollection, mockEntry, mockImageField)).toBe( - 'path/to/media/folder/i-am-a-title-fish', + '/path/to/media/folder/i-am-a-title-fish', ); }); @@ -383,7 +383,7 @@ describe('media.util', () => { }); expect(selectMediaFolder(mockConfig, mockCollection, mockEntry, mockImageField)).toBe( - 'path/to/some/other/media', + '/path/to/some/other/media/', ); }); }); diff --git a/packages/core/src/lib/util/media.util.ts b/packages/core/src/lib/util/media.util.ts index 609c38b3d..affc182d2 100644 --- a/packages/core/src/lib/util/media.util.ts +++ b/packages/core/src/lib/util/media.util.ts @@ -245,7 +245,7 @@ export function selectMediaFolder( } else if (hasCustomFolder('media_folder', collection, entryMap?.slug, field)) { const folder = evaluateFolder('media_folder', config, collection!, entryMap, field); if (folder.startsWith('/')) { - mediaFolder = folder.replace(/^[/]*/g, ''); + mediaFolder = folder; } else { const entryPath = entryMap?.path; mediaFolder = entryPath