diff --git a/lerna.json b/lerna.json index 3ce1e42a7..f71b982db 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "4.1.3" + "version": "4.2.0" } diff --git a/packages/app/package.json b/packages/app/package.json index f4a1b2eac..e88707846 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -1,6 +1,6 @@ { "name": "@staticcms/app", - "version": "4.1.3", + "version": "4.2.0", "license": "MIT", "description": "Static CMS application.", "repository": "https://github.com/StaticJsCMS/static-cms", @@ -39,7 +39,7 @@ "dependencies": { "@babel/eslint-parser": "7.23.3", "@babel/runtime": "7.23.7", - "@staticcms/core": "^4.1.3", + "@staticcms/core": "^4.2.0", "buffer": "6.0.3", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/packages/core/package.json b/packages/core/package.json index d3f933548..f88527f33 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@staticcms/core", - "version": "4.1.3", + "version": "4.2.0", "license": "MIT", "description": "Static CMS core application.", "repository": "https://github.com/StaticJsCMS/static-cms", diff --git a/packages/core/src/backend.ts b/packages/core/src/backend.ts index 3ba85272a..f1e416bf3 100644 --- a/packages/core/src/backend.ts +++ b/packages/core/src/backend.ts @@ -1118,6 +1118,7 @@ export class Backend = { collection?: CollectionWithDefaults; authorLogin?: string; authorName?: string; + data?: EntryData; }; export function commitMessageFormatter( type: keyof typeof commitMessageTemplates, config: ConfigWithDefaults, - { slug, path, collection, authorLogin, authorName }: Options, + { slug, path, collection, authorLogin, authorName, data }: Options, isOpenAuthoring?: boolean, ) { const templates = { ...commitMessageTemplates, ...(config.backend.commit_messages || {}) }; - + let explicitReplacement; const commitMessage = templates[type].replace(variableRegex, (_, variable) => { switch (variable) { case 'slug': @@ -64,6 +66,10 @@ export function commitMessageFormatter( case 'author-name': return authorName || ''; default: + explicitReplacement = getExplicitFieldReplacement(variable, data); + if (explicitReplacement) { + return explicitReplacement; + } console.warn( `[StaticCMS] Ignoring unknown variable “${variable}” in commit message template.`, ); diff --git a/packages/core/src/lib/util/media.util.ts b/packages/core/src/lib/util/media.util.ts index 99e2ac65e..a84110373 100644 --- a/packages/core/src/lib/util/media.util.ts +++ b/packages/core/src/lib/util/media.util.ts @@ -306,6 +306,8 @@ export function selectMediaFilePublicPath( if (mediaPath.startsWith(mediaFolder)) { return mediaPath.replace(mediaFolder, publicFolder); + } else if (mediaPath.startsWith(trim(mediaFolder, '/'))) { + return mediaPath.replace(trim(mediaFolder, '/'), publicFolder); } return mediaPath; diff --git a/packages/core/src/lib/widgets/stringTemplate.ts b/packages/core/src/lib/widgets/stringTemplate.ts index edf6733c4..322572ee7 100644 --- a/packages/core/src/lib/widgets/stringTemplate.ts +++ b/packages/core/src/lib/widgets/stringTemplate.ts @@ -187,7 +187,7 @@ export function expandPath({ // Allow `fields.` prefix in placeholder to override built in replacements // like "slug" and "year" with values from fields of the same name. -function getExplicitFieldReplacement(key: string, data: ObjectValue | undefined | null) { +export function getExplicitFieldReplacement(key: string, data: ObjectValue | undefined | null) { if (!key.startsWith(FIELD_PREFIX)) { return; } diff --git a/packages/demo/package.json b/packages/demo/package.json index 865b1380c..0676276de 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -32,7 +32,7 @@ "postcss": "8.4.32", "postcss-scss": "4.0.9", "prettier": "3.1.1", - "vite": "5.0.12", + "vite": "5.0.13", "vite-plugin-svgr": "4.2.0", "webpack": "5.89.0" }, diff --git a/packages/docs/content/docs/configuration-options.mdx b/packages/docs/content/docs/configuration-options.mdx index 857bf939f..e244ab69e 100644 --- a/packages/docs/content/docs/configuration-options.mdx +++ b/packages/docs/content/docs/configuration-options.mdx @@ -68,8 +68,8 @@ Static CMS generates the following commit types: | Commit type | When is it triggered? | Available template tags | | ------------- | ---------------------------- | ----------------------------------------------------------- | -| `create` | A new entry is created | `slug`, `path`, `collection`, `author-login`, `author-name` | -| `update` | An existing entry is changed | `slug`, `path`, `collection`, `author-login`, `author-name` | +| `create` | A new entry is created | `slug`, `path`, `collection`, `author-login`, `author-name`, `fields` | +| `update` | An existing entry is changed | `slug`, `path`, `collection`, `author-login`, `author-name`, `fields` | | `delete` | An existing entry is deleted | `slug`, `path`, `collection`, `author-login`, `author-name` | | `uploadMedia` | A media file is uploaded | `path`, `author-login`, `author-name` | | `deleteMedia` | A media file is deleted | `path`, `author-login`, `author-name` | @@ -83,6 +83,7 @@ Template tags produce the following output: - `{{path}}`: full path to the changed file - `{{author-login}}`: login/username of the author - `{{author-name}}`: full name of the author (might be empty based on the user's profile) +- `{{fields.[FIELD_NAME]}}`: A custom fields value ## Publish Mode diff --git a/packages/docs/content/releases.json b/packages/docs/content/releases.json index 9a7726558..c1828e9e4 100644 --- a/packages/docs/content/releases.json +++ b/packages/docs/content/releases.json @@ -1,5 +1,16 @@ { "releases": [ + { + "date": "2024-04-25T10:00:00.000Z", + "version": "v4.2.0", + "type": "minor", + "description": "Allow custom fields inside git commit message" + }, + { + "date": "2024-04-19T10:00:00.000Z", + "version": "v4.1.4", + "type": "patch" + }, { "date": "2024-03-13T10:00:00.000Z", "version": "v4.1.3", diff --git a/yarn.lock b/yarn.lock index 2d30a7972..1346a5080 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19550,10 +19550,10 @@ vite-plugin-svgr@4.2.0: "@svgr/core" "^8.1.0" "@svgr/plugin-jsx" "^8.1.0" -vite@5.0.12: - version "5.0.12" - resolved "https://registry.yarnpkg.com/vite/-/vite-5.0.12.tgz#8a2ffd4da36c132aec4adafe05d7adde38333c47" - integrity sha512-4hsnEkG3q0N4Tzf1+t6NdN9dg/L3BM+q8SWgbSPnJvrgH2kgdyzfVJwbR1ic69/4uMJJ/3dqDZZE5/WwqW8U1w== +vite@5.0.13: + version "5.0.13" + resolved "https://registry.yarnpkg.com/vite/-/vite-5.0.13.tgz#605865b0e482506163e3f04f91665238f3be8cf1" + integrity sha512-/9ovhv2M2dGTuA+dY93B9trfyWMDRQw2jdVBhHNP6wr0oF34wG2i/N55801iZIpgUpnHDm4F/FabGQLyc+eOgg== dependencies: esbuild "^0.19.3" postcss "^8.4.32"