@littlebox/strapi-suite 1.0.34 → 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -33
- package/dist/_chunks/{App-DyjWjB7j.mjs → App-2SwRpCFC.mjs} +111 -22
- package/dist/_chunks/{App-BHSmVWtI.js → App-DBXgA-D1.js} +111 -22
- package/dist/_chunks/{SlugInput-Blvf1j9x.mjs → SlugInput-BcUe-oCY.mjs} +2 -2
- package/dist/_chunks/{SlugInput-6ZNFcvBl.js → SlugInput-CVnNz0al.js} +2 -2
- package/dist/_chunks/{convertToSlug-CTdv5t0Z.js → convertToSlug-Btfca6aI.js} +1 -1
- package/dist/_chunks/{convertToSlug-Cc3NGUTL.mjs → convertToSlug-q9_W-VMA.mjs} +1 -1
- package/dist/_chunks/{en-B02DK8eB.js → en-CGJcJfk1.js} +3 -0
- package/dist/_chunks/{en-Gbpe0cex.mjs → en-CRSiVe4w.mjs} +3 -0
- package/dist/_chunks/{index-JYGAi1yZ.mjs → index-DmkEUACh.mjs} +10 -6
- package/dist/_chunks/{index-DXJ64IZL.js → index-Pylfg-hk.js} +7 -3
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/core/config.d.ts +2 -0
- package/dist/server/index.js +102 -35
- package/dist/server/index.mjs +102 -35
- package/dist/server/src/config/index.d.ts +2 -0
- package/dist/server/src/index.d.ts +1 -7
- package/dist/server/src/services/index.d.ts +1 -7
- package/dist/server/src/services/modules/slug.d.ts +1 -7
- package/package.json +1 -1
|
@@ -57,6 +57,9 @@ const en = {
|
|
|
57
57
|
"littlebox-strapi-suite.module.slug.modal.settings.input.default-language.description": "Show language slug for default language in site url",
|
|
58
58
|
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage.title": "Home page",
|
|
59
59
|
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage.description": "The content that will be rendered as the homepage",
|
|
60
|
+
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage-strategy.title": "Home page slug strategy",
|
|
61
|
+
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage-strategy.description.language": "Use the language slug and ignore the content slug set as the homepage",
|
|
62
|
+
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage-strategy.description.content": "Use the slug of the content set as the homepage",
|
|
60
63
|
"littlebox-strapi-suite.module.slug.modal.settings.button.save": "Save",
|
|
61
64
|
"littlebox-strapi-suite.module.attribute.name": "Attribute",
|
|
62
65
|
"littlebox-strapi-suite.module.attribute.description": "Effortlessly customize any page with simple and flexible attribute options.",
|
|
@@ -55,6 +55,9 @@ const en = {
|
|
|
55
55
|
"littlebox-strapi-suite.module.slug.modal.settings.input.default-language.description": "Show language slug for default language in site url",
|
|
56
56
|
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage.title": "Home page",
|
|
57
57
|
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage.description": "The content that will be rendered as the homepage",
|
|
58
|
+
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage-strategy.title": "Home page slug strategy",
|
|
59
|
+
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage-strategy.description.language": "Use the language slug and ignore the content slug set as the homepage",
|
|
60
|
+
"littlebox-strapi-suite.module.slug.modal.settings.input.homepage-strategy.description.content": "Use the slug of the content set as the homepage",
|
|
58
61
|
"littlebox-strapi-suite.module.slug.modal.settings.button.save": "Save",
|
|
59
62
|
"littlebox-strapi-suite.module.attribute.name": "Attribute",
|
|
60
63
|
"littlebox-strapi-suite.module.attribute.description": "Effortlessly customize any page with simple and flexible attribute options.",
|
|
@@ -2597,6 +2597,8 @@ function makeNodesHash(arr) {
|
|
|
2597
2597
|
return res;
|
|
2598
2598
|
}
|
|
2599
2599
|
const PLUGIN_ID = "littlebox-strapi-suite";
|
|
2600
|
+
const SLUG_LANGUAGE_STRATEGY = "language";
|
|
2601
|
+
const SLUG_CONTENT_STRATEGY = "content";
|
|
2600
2602
|
const config = {
|
|
2601
2603
|
pluginId: PLUGIN_ID,
|
|
2602
2604
|
uuid: {
|
|
@@ -3301,7 +3303,7 @@ const index = {
|
|
|
3301
3303
|
defaultMessage: config.pluginId
|
|
3302
3304
|
},
|
|
3303
3305
|
position: 999,
|
|
3304
|
-
Component: () => import("./App-
|
|
3306
|
+
Component: () => import("./App-2SwRpCFC.mjs")
|
|
3305
3307
|
});
|
|
3306
3308
|
app.customFields.register({
|
|
3307
3309
|
name: "ltbslug",
|
|
@@ -3319,7 +3321,7 @@ const index = {
|
|
|
3319
3321
|
components: {
|
|
3320
3322
|
Input: async () => import(
|
|
3321
3323
|
/* webpackChunkName: "input-slug-component" */
|
|
3322
|
-
"./SlugInput-
|
|
3324
|
+
"./SlugInput-BcUe-oCY.mjs"
|
|
3323
3325
|
)
|
|
3324
3326
|
},
|
|
3325
3327
|
options: {
|
|
@@ -3371,7 +3373,7 @@ const index = {
|
|
|
3371
3373
|
return Promise.all(
|
|
3372
3374
|
locales.map(async (locale) => {
|
|
3373
3375
|
try {
|
|
3374
|
-
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => import("./en-
|
|
3376
|
+
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => import("./en-CRSiVe4w.mjs") }), `./core/translations/${locale}.json`, 4);
|
|
3375
3377
|
return { data, locale };
|
|
3376
3378
|
} catch {
|
|
3377
3379
|
return { data: {}, locale };
|
|
@@ -3398,10 +3400,12 @@ export {
|
|
|
3398
3400
|
FetchSettings as F,
|
|
3399
3401
|
PageAttributeUpdated as P,
|
|
3400
3402
|
Registry as R,
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
+
SLUG_LANGUAGE_STRATEGY as S,
|
|
3404
|
+
SLUG_CONTENT_STRATEGY as a,
|
|
3405
|
+
FetchSlugs as b,
|
|
3403
3406
|
config as c,
|
|
3404
|
-
|
|
3407
|
+
PluginIcon as d,
|
|
3408
|
+
FetchModuleSettings as e,
|
|
3405
3409
|
fetchTemplates as f,
|
|
3406
3410
|
getTranslation as g,
|
|
3407
3411
|
index as i
|
|
@@ -2600,6 +2600,8 @@ function makeNodesHash(arr) {
|
|
|
2600
2600
|
return res;
|
|
2601
2601
|
}
|
|
2602
2602
|
const PLUGIN_ID = "littlebox-strapi-suite";
|
|
2603
|
+
const SLUG_LANGUAGE_STRATEGY = "language";
|
|
2604
|
+
const SLUG_CONTENT_STRATEGY = "content";
|
|
2603
2605
|
const config = {
|
|
2604
2606
|
pluginId: PLUGIN_ID,
|
|
2605
2607
|
uuid: {
|
|
@@ -3304,7 +3306,7 @@ const index = {
|
|
|
3304
3306
|
defaultMessage: config.pluginId
|
|
3305
3307
|
},
|
|
3306
3308
|
position: 999,
|
|
3307
|
-
Component: () => Promise.resolve().then(() => require("./App-
|
|
3309
|
+
Component: () => Promise.resolve().then(() => require("./App-DBXgA-D1.js"))
|
|
3308
3310
|
});
|
|
3309
3311
|
app.customFields.register({
|
|
3310
3312
|
name: "ltbslug",
|
|
@@ -3322,7 +3324,7 @@ const index = {
|
|
|
3322
3324
|
components: {
|
|
3323
3325
|
Input: async () => Promise.resolve().then(() => require(
|
|
3324
3326
|
/* webpackChunkName: "input-slug-component" */
|
|
3325
|
-
"./SlugInput-
|
|
3327
|
+
"./SlugInput-CVnNz0al.js"
|
|
3326
3328
|
))
|
|
3327
3329
|
},
|
|
3328
3330
|
options: {
|
|
@@ -3374,7 +3376,7 @@ const index = {
|
|
|
3374
3376
|
return Promise.all(
|
|
3375
3377
|
locales.map(async (locale) => {
|
|
3376
3378
|
try {
|
|
3377
|
-
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => Promise.resolve().then(() => require("./en-
|
|
3379
|
+
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => Promise.resolve().then(() => require("./en-CGJcJfk1.js")) }), `./core/translations/${locale}.json`, 4);
|
|
3378
3380
|
return { data, locale };
|
|
3379
3381
|
} catch {
|
|
3380
3382
|
return { data: {}, locale };
|
|
@@ -3403,6 +3405,8 @@ exports.FetchSlugs = FetchSlugs;
|
|
|
3403
3405
|
exports.PageAttributeUpdated = PageAttributeUpdated;
|
|
3404
3406
|
exports.PluginIcon = PluginIcon;
|
|
3405
3407
|
exports.Registry = Registry;
|
|
3408
|
+
exports.SLUG_CONTENT_STRATEGY = SLUG_CONTENT_STRATEGY;
|
|
3409
|
+
exports.SLUG_LANGUAGE_STRATEGY = SLUG_LANGUAGE_STRATEGY;
|
|
3406
3410
|
exports.config = config;
|
|
3407
3411
|
exports.fetchTemplates = fetchTemplates;
|
|
3408
3412
|
exports.getTranslation = getTranslation;
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const PLUGIN_ID = "littlebox-strapi-suite";
|
|
3
|
+
const SLUG_LANGUAGE_STRATEGY = "language";
|
|
3
4
|
const config = {
|
|
4
5
|
default: {
|
|
5
6
|
pluginId: PLUGIN_ID,
|
|
@@ -458,6 +459,12 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
458
459
|
property: "homepageContentModel",
|
|
459
460
|
type: "string",
|
|
460
461
|
value: null
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
module: "slug",
|
|
465
|
+
property: "homepageSlugStrategy",
|
|
466
|
+
type: "string",
|
|
467
|
+
value: "language"
|
|
461
468
|
}
|
|
462
469
|
]
|
|
463
470
|
});
|
|
@@ -1653,24 +1660,42 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1653
1660
|
const ctx = strapi2.requestContext.get();
|
|
1654
1661
|
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1655
1662
|
const slug = ctx.query.slug.replace(/^\/|\/$/g, "");
|
|
1663
|
+
const locales = await strapi2.plugin("i18n").service("locales").find();
|
|
1664
|
+
const mappedLocales = locales.map((locale) => locale.code.toLowerCase());
|
|
1656
1665
|
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1657
|
-
const
|
|
1666
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1658
1667
|
where: {
|
|
1659
1668
|
module: "slug",
|
|
1660
|
-
property: "showDefaultLanguage"
|
|
1661
|
-
}
|
|
1662
|
-
});
|
|
1663
|
-
const showDefaultLanguage = setting.value === "true";
|
|
1664
|
-
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1665
|
-
where: {
|
|
1666
|
-
state: "published",
|
|
1667
|
-
slug: slug.split("/")
|
|
1669
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1668
1670
|
}
|
|
1669
1671
|
});
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
const
|
|
1672
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1673
|
+
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1674
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1675
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1676
|
+
let page;
|
|
1677
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && mappedLocales.includes(slug)) {
|
|
1678
|
+
page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
1679
|
+
where: {
|
|
1680
|
+
state: "published",
|
|
1681
|
+
contentId: homepageContentId,
|
|
1682
|
+
contentModel: homepageContentModel,
|
|
1683
|
+
locale: slug
|
|
1684
|
+
}
|
|
1685
|
+
});
|
|
1686
|
+
page.fullSlug = slug;
|
|
1687
|
+
} else {
|
|
1688
|
+
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1689
|
+
where: {
|
|
1690
|
+
state: "published",
|
|
1691
|
+
slug: slug.split("/")
|
|
1692
|
+
}
|
|
1693
|
+
});
|
|
1694
|
+
pages.forEach((page2) => {
|
|
1695
|
+
page2.fullSlug = buildFullSlug({ pages, page: page2, defaultLocale, showDefaultLanguage });
|
|
1696
|
+
});
|
|
1697
|
+
page = pages.find((page2) => page2.fullSlug === slug);
|
|
1698
|
+
}
|
|
1674
1699
|
if (!page) {
|
|
1675
1700
|
ctx.status = 404;
|
|
1676
1701
|
return;
|
|
@@ -1704,13 +1729,17 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1704
1729
|
documentId: page.contentId
|
|
1705
1730
|
});
|
|
1706
1731
|
for (const localization of document.localizations) {
|
|
1707
|
-
localization.
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1732
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && localization.documentId === homepageContentId) {
|
|
1733
|
+
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
1734
|
+
} else {
|
|
1735
|
+
localization.slug = await getSlugByDocumentId({
|
|
1736
|
+
contentId: localization.documentId,
|
|
1737
|
+
locale: localization.locale,
|
|
1738
|
+
defaultLocale,
|
|
1739
|
+
showDefaultLanguage,
|
|
1740
|
+
strapi: strapi2
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1714
1743
|
}
|
|
1715
1744
|
delete document.createdBy;
|
|
1716
1745
|
delete document.updatedBy;
|
|
@@ -1728,22 +1757,23 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1728
1757
|
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1729
1758
|
where: {
|
|
1730
1759
|
module: "slug",
|
|
1731
|
-
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel"]
|
|
1760
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1732
1761
|
}
|
|
1733
1762
|
});
|
|
1734
1763
|
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1735
1764
|
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1736
|
-
settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1765
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1766
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1737
1767
|
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1738
1768
|
where: {
|
|
1739
1769
|
state: "published"
|
|
1740
1770
|
}
|
|
1741
1771
|
});
|
|
1742
1772
|
pages.forEach((page) => {
|
|
1743
|
-
if (homepageContentId === page.contentId && defaultLocale === page.locale) {
|
|
1773
|
+
if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale === page.locale) {
|
|
1744
1774
|
page.fullSlug = "";
|
|
1745
|
-
} else if (homepageContentId === page.contentId && defaultLocale !== page.locale) {
|
|
1746
|
-
page.fullSlug = page.locale;
|
|
1775
|
+
} else if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale !== page.locale && homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
1776
|
+
page.fullSlug = page.locale.toLowerCase();
|
|
1747
1777
|
} else {
|
|
1748
1778
|
page.fullSlug = buildFullSlug({ pages, page, defaultLocale, showDefaultLanguage });
|
|
1749
1779
|
}
|
|
@@ -1772,13 +1802,37 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1772
1802
|
}
|
|
1773
1803
|
}
|
|
1774
1804
|
const mappedPages = pages.map((page) => ({
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
locale: page.locale,
|
|
1779
|
-
...page.attributes ? { attributes: page.attributes } : {}
|
|
1805
|
+
...page,
|
|
1806
|
+
...page.attributes ? { attributes: page.attributes } : {},
|
|
1807
|
+
localizations: []
|
|
1780
1808
|
}));
|
|
1781
|
-
|
|
1809
|
+
const rootItems = mappedPages.filter((item) => item.locale === defaultLocale);
|
|
1810
|
+
const mappedItems = rootItems.map((rootItem) => {
|
|
1811
|
+
const relatedItems = mappedPages.filter(
|
|
1812
|
+
(item) => item.contentId === rootItem.contentId && item.contentModel === rootItem.contentModel && item.locale !== defaultLocale
|
|
1813
|
+
);
|
|
1814
|
+
return {
|
|
1815
|
+
id: rootItem.id,
|
|
1816
|
+
documentId: rootItem.contentId,
|
|
1817
|
+
slug: rootItem.fullSlug,
|
|
1818
|
+
locale: rootItem.locale,
|
|
1819
|
+
createdAt: rootItem.updatedAt,
|
|
1820
|
+
updatedAt: rootItem.updatedAt,
|
|
1821
|
+
publishedAt: rootItem.updatedAt,
|
|
1822
|
+
...rootItem.attributes ? { attributes: rootItem.attributes } : {},
|
|
1823
|
+
localizations: relatedItems.map((item) => ({
|
|
1824
|
+
id: item.id,
|
|
1825
|
+
documentId: item.contentId,
|
|
1826
|
+
slug: item.fullSlug,
|
|
1827
|
+
locale: item.locale,
|
|
1828
|
+
createdAt: item.updatedAt,
|
|
1829
|
+
updatedAt: item.updatedAt,
|
|
1830
|
+
publishedAt: item.updatedAt,
|
|
1831
|
+
...item.attributes ? { attributes: item.attributes } : {}
|
|
1832
|
+
}))
|
|
1833
|
+
};
|
|
1834
|
+
});
|
|
1835
|
+
return mappedItems;
|
|
1782
1836
|
},
|
|
1783
1837
|
async getHomePage() {
|
|
1784
1838
|
const ctx = strapi2.requestContext.get();
|
|
@@ -1787,16 +1841,19 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1787
1841
|
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1788
1842
|
where: {
|
|
1789
1843
|
module: "slug",
|
|
1790
|
-
property: ["homepageContentId", "homepageContentModel"]
|
|
1844
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1791
1845
|
}
|
|
1792
1846
|
});
|
|
1847
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1793
1848
|
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1794
1849
|
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1850
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1795
1851
|
const page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
1796
1852
|
where: {
|
|
1797
1853
|
state: "published",
|
|
1798
1854
|
contentId: homepageContentId,
|
|
1799
|
-
contentModel: homepageContentModel
|
|
1855
|
+
contentModel: homepageContentModel,
|
|
1856
|
+
locale: defaultLocale
|
|
1800
1857
|
}
|
|
1801
1858
|
});
|
|
1802
1859
|
if (!page) {
|
|
@@ -1832,11 +1889,21 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1832
1889
|
documentId: page.contentId
|
|
1833
1890
|
});
|
|
1834
1891
|
for (const localization of document.localizations) {
|
|
1835
|
-
|
|
1892
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
1893
|
+
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
1894
|
+
} else {
|
|
1895
|
+
localization.slug = await getSlugByDocumentId({
|
|
1896
|
+
contentId: localization.documentId,
|
|
1897
|
+
locale: localization.locale,
|
|
1898
|
+
defaultLocale,
|
|
1899
|
+
showDefaultLanguage,
|
|
1900
|
+
strapi: strapi2
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1836
1903
|
}
|
|
1837
1904
|
delete document.createdBy;
|
|
1838
1905
|
delete document.updatedBy;
|
|
1839
|
-
document.slug =
|
|
1906
|
+
document.slug = "";
|
|
1840
1907
|
return {
|
|
1841
1908
|
document,
|
|
1842
1909
|
...page.attributes ? { attributes: page.attributes } : {}
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const PLUGIN_ID = "littlebox-strapi-suite";
|
|
2
|
+
const SLUG_LANGUAGE_STRATEGY = "language";
|
|
2
3
|
const config = {
|
|
3
4
|
default: {
|
|
4
5
|
pluginId: PLUGIN_ID,
|
|
@@ -457,6 +458,12 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
457
458
|
property: "homepageContentModel",
|
|
458
459
|
type: "string",
|
|
459
460
|
value: null
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
module: "slug",
|
|
464
|
+
property: "homepageSlugStrategy",
|
|
465
|
+
type: "string",
|
|
466
|
+
value: "language"
|
|
460
467
|
}
|
|
461
468
|
]
|
|
462
469
|
});
|
|
@@ -1652,24 +1659,42 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1652
1659
|
const ctx = strapi2.requestContext.get();
|
|
1653
1660
|
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1654
1661
|
const slug = ctx.query.slug.replace(/^\/|\/$/g, "");
|
|
1662
|
+
const locales = await strapi2.plugin("i18n").service("locales").find();
|
|
1663
|
+
const mappedLocales = locales.map((locale) => locale.code.toLowerCase());
|
|
1655
1664
|
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1656
|
-
const
|
|
1665
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1657
1666
|
where: {
|
|
1658
1667
|
module: "slug",
|
|
1659
|
-
property: "showDefaultLanguage"
|
|
1660
|
-
}
|
|
1661
|
-
});
|
|
1662
|
-
const showDefaultLanguage = setting.value === "true";
|
|
1663
|
-
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1664
|
-
where: {
|
|
1665
|
-
state: "published",
|
|
1666
|
-
slug: slug.split("/")
|
|
1668
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1667
1669
|
}
|
|
1668
1670
|
});
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
const
|
|
1671
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1672
|
+
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1673
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1674
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1675
|
+
let page;
|
|
1676
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && mappedLocales.includes(slug)) {
|
|
1677
|
+
page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
1678
|
+
where: {
|
|
1679
|
+
state: "published",
|
|
1680
|
+
contentId: homepageContentId,
|
|
1681
|
+
contentModel: homepageContentModel,
|
|
1682
|
+
locale: slug
|
|
1683
|
+
}
|
|
1684
|
+
});
|
|
1685
|
+
page.fullSlug = slug;
|
|
1686
|
+
} else {
|
|
1687
|
+
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1688
|
+
where: {
|
|
1689
|
+
state: "published",
|
|
1690
|
+
slug: slug.split("/")
|
|
1691
|
+
}
|
|
1692
|
+
});
|
|
1693
|
+
pages.forEach((page2) => {
|
|
1694
|
+
page2.fullSlug = buildFullSlug({ pages, page: page2, defaultLocale, showDefaultLanguage });
|
|
1695
|
+
});
|
|
1696
|
+
page = pages.find((page2) => page2.fullSlug === slug);
|
|
1697
|
+
}
|
|
1673
1698
|
if (!page) {
|
|
1674
1699
|
ctx.status = 404;
|
|
1675
1700
|
return;
|
|
@@ -1703,13 +1728,17 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1703
1728
|
documentId: page.contentId
|
|
1704
1729
|
});
|
|
1705
1730
|
for (const localization of document.localizations) {
|
|
1706
|
-
localization.
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1731
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && localization.documentId === homepageContentId) {
|
|
1732
|
+
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
1733
|
+
} else {
|
|
1734
|
+
localization.slug = await getSlugByDocumentId({
|
|
1735
|
+
contentId: localization.documentId,
|
|
1736
|
+
locale: localization.locale,
|
|
1737
|
+
defaultLocale,
|
|
1738
|
+
showDefaultLanguage,
|
|
1739
|
+
strapi: strapi2
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1713
1742
|
}
|
|
1714
1743
|
delete document.createdBy;
|
|
1715
1744
|
delete document.updatedBy;
|
|
@@ -1727,22 +1756,23 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1727
1756
|
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1728
1757
|
where: {
|
|
1729
1758
|
module: "slug",
|
|
1730
|
-
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel"]
|
|
1759
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1731
1760
|
}
|
|
1732
1761
|
});
|
|
1733
1762
|
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1734
1763
|
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1735
|
-
settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1764
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1765
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1736
1766
|
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1737
1767
|
where: {
|
|
1738
1768
|
state: "published"
|
|
1739
1769
|
}
|
|
1740
1770
|
});
|
|
1741
1771
|
pages.forEach((page) => {
|
|
1742
|
-
if (homepageContentId === page.contentId && defaultLocale === page.locale) {
|
|
1772
|
+
if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale === page.locale) {
|
|
1743
1773
|
page.fullSlug = "";
|
|
1744
|
-
} else if (homepageContentId === page.contentId && defaultLocale !== page.locale) {
|
|
1745
|
-
page.fullSlug = page.locale;
|
|
1774
|
+
} else if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale !== page.locale && homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
1775
|
+
page.fullSlug = page.locale.toLowerCase();
|
|
1746
1776
|
} else {
|
|
1747
1777
|
page.fullSlug = buildFullSlug({ pages, page, defaultLocale, showDefaultLanguage });
|
|
1748
1778
|
}
|
|
@@ -1771,13 +1801,37 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1771
1801
|
}
|
|
1772
1802
|
}
|
|
1773
1803
|
const mappedPages = pages.map((page) => ({
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
locale: page.locale,
|
|
1778
|
-
...page.attributes ? { attributes: page.attributes } : {}
|
|
1804
|
+
...page,
|
|
1805
|
+
...page.attributes ? { attributes: page.attributes } : {},
|
|
1806
|
+
localizations: []
|
|
1779
1807
|
}));
|
|
1780
|
-
|
|
1808
|
+
const rootItems = mappedPages.filter((item) => item.locale === defaultLocale);
|
|
1809
|
+
const mappedItems = rootItems.map((rootItem) => {
|
|
1810
|
+
const relatedItems = mappedPages.filter(
|
|
1811
|
+
(item) => item.contentId === rootItem.contentId && item.contentModel === rootItem.contentModel && item.locale !== defaultLocale
|
|
1812
|
+
);
|
|
1813
|
+
return {
|
|
1814
|
+
id: rootItem.id,
|
|
1815
|
+
documentId: rootItem.contentId,
|
|
1816
|
+
slug: rootItem.fullSlug,
|
|
1817
|
+
locale: rootItem.locale,
|
|
1818
|
+
createdAt: rootItem.updatedAt,
|
|
1819
|
+
updatedAt: rootItem.updatedAt,
|
|
1820
|
+
publishedAt: rootItem.updatedAt,
|
|
1821
|
+
...rootItem.attributes ? { attributes: rootItem.attributes } : {},
|
|
1822
|
+
localizations: relatedItems.map((item) => ({
|
|
1823
|
+
id: item.id,
|
|
1824
|
+
documentId: item.contentId,
|
|
1825
|
+
slug: item.fullSlug,
|
|
1826
|
+
locale: item.locale,
|
|
1827
|
+
createdAt: item.updatedAt,
|
|
1828
|
+
updatedAt: item.updatedAt,
|
|
1829
|
+
publishedAt: item.updatedAt,
|
|
1830
|
+
...item.attributes ? { attributes: item.attributes } : {}
|
|
1831
|
+
}))
|
|
1832
|
+
};
|
|
1833
|
+
});
|
|
1834
|
+
return mappedItems;
|
|
1781
1835
|
},
|
|
1782
1836
|
async getHomePage() {
|
|
1783
1837
|
const ctx = strapi2.requestContext.get();
|
|
@@ -1786,16 +1840,19 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1786
1840
|
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1787
1841
|
where: {
|
|
1788
1842
|
module: "slug",
|
|
1789
|
-
property: ["homepageContentId", "homepageContentModel"]
|
|
1843
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1790
1844
|
}
|
|
1791
1845
|
});
|
|
1846
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1792
1847
|
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1793
1848
|
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1849
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1794
1850
|
const page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
1795
1851
|
where: {
|
|
1796
1852
|
state: "published",
|
|
1797
1853
|
contentId: homepageContentId,
|
|
1798
|
-
contentModel: homepageContentModel
|
|
1854
|
+
contentModel: homepageContentModel,
|
|
1855
|
+
locale: defaultLocale
|
|
1799
1856
|
}
|
|
1800
1857
|
});
|
|
1801
1858
|
if (!page) {
|
|
@@ -1831,11 +1888,21 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1831
1888
|
documentId: page.contentId
|
|
1832
1889
|
});
|
|
1833
1890
|
for (const localization of document.localizations) {
|
|
1834
|
-
|
|
1891
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
1892
|
+
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
1893
|
+
} else {
|
|
1894
|
+
localization.slug = await getSlugByDocumentId({
|
|
1895
|
+
contentId: localization.documentId,
|
|
1896
|
+
locale: localization.locale,
|
|
1897
|
+
defaultLocale,
|
|
1898
|
+
showDefaultLanguage,
|
|
1899
|
+
strapi: strapi2
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1835
1902
|
}
|
|
1836
1903
|
delete document.createdBy;
|
|
1837
1904
|
delete document.updatedBy;
|
|
1838
|
-
document.slug =
|
|
1905
|
+
document.slug = "";
|
|
1839
1906
|
return {
|
|
1840
1907
|
document,
|
|
1841
1908
|
...page.attributes ? { attributes: page.attributes } : {}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { UID } from "@strapi/strapi";
|
|
2
2
|
export declare const PLUGIN_ID = "littlebox-strapi-suite";
|
|
3
|
+
export declare const SLUG_LANGUAGE_STRATEGY = "language";
|
|
4
|
+
export declare const SLUG_CONTENT_STRATEGY = "content";
|
|
3
5
|
export interface LtbConfigs {
|
|
4
6
|
pluginId: string;
|
|
5
7
|
uuid: {
|
|
@@ -145,13 +145,7 @@ declare const _default: {
|
|
|
145
145
|
attributes?: any;
|
|
146
146
|
document: import("@strapi/types/dist/modules/documents").AnyDocument;
|
|
147
147
|
}>;
|
|
148
|
-
getPages(): Promise<
|
|
149
|
-
attributes?: any;
|
|
150
|
-
id: any;
|
|
151
|
-
model: any;
|
|
152
|
-
slug: any;
|
|
153
|
-
locale: any;
|
|
154
|
-
}[]>;
|
|
148
|
+
getPages(): Promise<any[]>;
|
|
155
149
|
getHomePage(): Promise<{
|
|
156
150
|
attributes?: any;
|
|
157
151
|
document: import("@strapi/types/dist/modules/documents").AnyDocument;
|
|
@@ -15,13 +15,7 @@ declare const _default: {
|
|
|
15
15
|
attributes?: any;
|
|
16
16
|
document: import("@strapi/types/dist/modules/documents").AnyDocument;
|
|
17
17
|
}>;
|
|
18
|
-
getPages(): Promise<
|
|
19
|
-
attributes?: any;
|
|
20
|
-
id: any;
|
|
21
|
-
model: any;
|
|
22
|
-
slug: any;
|
|
23
|
-
locale: any;
|
|
24
|
-
}[]>;
|
|
18
|
+
getPages(): Promise<any[]>;
|
|
25
19
|
getHomePage(): Promise<{
|
|
26
20
|
attributes?: any;
|
|
27
21
|
document: import("@strapi/types/dist/modules/documents").AnyDocument;
|
|
@@ -8,13 +8,7 @@ declare const SlugModuleService: ({ strapi }: {
|
|
|
8
8
|
attributes?: any;
|
|
9
9
|
document: import("@strapi/types/dist/modules/documents").AnyDocument;
|
|
10
10
|
}>;
|
|
11
|
-
getPages(): Promise<
|
|
12
|
-
attributes?: any;
|
|
13
|
-
id: any;
|
|
14
|
-
model: any;
|
|
15
|
-
slug: any;
|
|
16
|
-
locale: any;
|
|
17
|
-
}[]>;
|
|
11
|
+
getPages(): Promise<any[]>;
|
|
18
12
|
getHomePage(): Promise<{
|
|
19
13
|
attributes?: any;
|
|
20
14
|
document: import("@strapi/types/dist/modules/documents").AnyDocument;
|
package/package.json
CHANGED