@littlebox/strapi-suite 1.0.34 → 1.0.36
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 +138 -49
- package/dist/server/index.mjs +138 -49
- package/dist/server/src/config/index.d.ts +2 -0
- package/dist/server/src/controllers/index.d.ts +8 -0
- package/dist/server/src/controllers/modules/locales.d.ts +10 -0
- package/dist/server/src/index.d.ts +9 -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
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,
|
|
@@ -433,19 +434,6 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
433
434
|
type: "boolean",
|
|
434
435
|
value: "false"
|
|
435
436
|
},
|
|
436
|
-
{
|
|
437
|
-
module: "template",
|
|
438
|
-
property: "active",
|
|
439
|
-
type: "boolean",
|
|
440
|
-
value: "true"
|
|
441
|
-
}
|
|
442
|
-
]
|
|
443
|
-
});
|
|
444
|
-
} catch (e) {
|
|
445
|
-
}
|
|
446
|
-
try {
|
|
447
|
-
await strapi2.db.query(config2.uuid.app.setting).createMany({
|
|
448
|
-
data: [
|
|
449
437
|
{
|
|
450
438
|
module: "slug",
|
|
451
439
|
property: "homepageContentId",
|
|
@@ -457,6 +445,24 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
457
445
|
property: "homepageContentModel",
|
|
458
446
|
type: "string",
|
|
459
447
|
value: null
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
module: "slug",
|
|
451
|
+
property: "homepageSlugStrategy",
|
|
452
|
+
type: "string",
|
|
453
|
+
value: "language"
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
module: "template",
|
|
457
|
+
property: "active",
|
|
458
|
+
type: "boolean",
|
|
459
|
+
value: "true"
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
module: "locale",
|
|
463
|
+
property: "active",
|
|
464
|
+
type: "boolean",
|
|
465
|
+
value: "true"
|
|
460
466
|
}
|
|
461
467
|
]
|
|
462
468
|
});
|
|
@@ -1192,6 +1198,17 @@ const TranslationModuleController = ({ strapi: strapi2 }) => ({
|
|
|
1192
1198
|
return await strapi2.plugin(PLUGIN_ID).service("TranslationModuleService").getTranslations();
|
|
1193
1199
|
}
|
|
1194
1200
|
});
|
|
1201
|
+
const LocalesModuleController = ({ strapi: strapi2 }) => ({
|
|
1202
|
+
async getLocales() {
|
|
1203
|
+
const locales = await strapi2.plugin("i18n").service("locales").find();
|
|
1204
|
+
const mappedLocales = locales.map((locale) => locale.code.toLowerCase());
|
|
1205
|
+
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1206
|
+
return {
|
|
1207
|
+
locales: mappedLocales,
|
|
1208
|
+
default: defaultLocale
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1195
1212
|
const controllers = {
|
|
1196
1213
|
SettingAppController,
|
|
1197
1214
|
SlugModuleController,
|
|
@@ -1199,10 +1216,12 @@ const controllers = {
|
|
|
1199
1216
|
TemplateModuleController,
|
|
1200
1217
|
MenuModuleController,
|
|
1201
1218
|
ParameterModuleController,
|
|
1202
|
-
TranslationModuleController
|
|
1219
|
+
TranslationModuleController,
|
|
1220
|
+
LocalesModuleController
|
|
1203
1221
|
};
|
|
1204
1222
|
function getModuleName(url) {
|
|
1205
1223
|
if (url.includes("/pages")) return "slug";
|
|
1224
|
+
if (url.includes("/locales")) return "locale";
|
|
1206
1225
|
if (url.includes("/parameters")) return "parameter";
|
|
1207
1226
|
if (url.includes("/translations")) return "translation";
|
|
1208
1227
|
if (url.includes("/menus")) return "menu";
|
|
@@ -1300,6 +1319,16 @@ const contentAPIRoutes = [
|
|
|
1300
1319
|
policies: ["check-api-token"],
|
|
1301
1320
|
auth: false
|
|
1302
1321
|
}
|
|
1322
|
+
},
|
|
1323
|
+
{
|
|
1324
|
+
method: "GET",
|
|
1325
|
+
path: "/modules/locales",
|
|
1326
|
+
handler: "LocalesModuleController.getLocales",
|
|
1327
|
+
config: {
|
|
1328
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1329
|
+
policies: ["check-api-token"],
|
|
1330
|
+
auth: false
|
|
1331
|
+
}
|
|
1303
1332
|
}
|
|
1304
1333
|
];
|
|
1305
1334
|
const adminAPIRoutes = [
|
|
@@ -1652,24 +1681,42 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1652
1681
|
const ctx = strapi2.requestContext.get();
|
|
1653
1682
|
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1654
1683
|
const slug = ctx.query.slug.replace(/^\/|\/$/g, "");
|
|
1684
|
+
const locales = await strapi2.plugin("i18n").service("locales").find();
|
|
1685
|
+
const mappedLocales = locales.map((locale) => locale.code.toLowerCase());
|
|
1655
1686
|
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1656
|
-
const
|
|
1687
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1657
1688
|
where: {
|
|
1658
1689
|
module: "slug",
|
|
1659
|
-
property: "showDefaultLanguage"
|
|
1690
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1660
1691
|
}
|
|
1661
1692
|
});
|
|
1662
|
-
const showDefaultLanguage = setting.value === "true";
|
|
1663
|
-
const
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1693
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1694
|
+
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1695
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1696
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1697
|
+
let page;
|
|
1698
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && mappedLocales.includes(slug)) {
|
|
1699
|
+
page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
1700
|
+
where: {
|
|
1701
|
+
state: "published",
|
|
1702
|
+
contentId: homepageContentId,
|
|
1703
|
+
contentModel: homepageContentModel,
|
|
1704
|
+
locale: slug
|
|
1705
|
+
}
|
|
1706
|
+
});
|
|
1707
|
+
page.fullSlug = slug;
|
|
1708
|
+
} else {
|
|
1709
|
+
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1710
|
+
where: {
|
|
1711
|
+
state: "published",
|
|
1712
|
+
slug: slug.split("/")
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
pages.forEach((page2) => {
|
|
1716
|
+
page2.fullSlug = buildFullSlug({ pages, page: page2, defaultLocale, showDefaultLanguage });
|
|
1717
|
+
});
|
|
1718
|
+
page = pages.find((page2) => page2.fullSlug === slug);
|
|
1719
|
+
}
|
|
1673
1720
|
if (!page) {
|
|
1674
1721
|
ctx.status = 404;
|
|
1675
1722
|
return;
|
|
@@ -1703,13 +1750,17 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1703
1750
|
documentId: page.contentId
|
|
1704
1751
|
});
|
|
1705
1752
|
for (const localization of document.localizations) {
|
|
1706
|
-
localization.
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1753
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && localization.documentId === homepageContentId) {
|
|
1754
|
+
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
1755
|
+
} else {
|
|
1756
|
+
localization.slug = await getSlugByDocumentId({
|
|
1757
|
+
contentId: localization.documentId,
|
|
1758
|
+
locale: localization.locale,
|
|
1759
|
+
defaultLocale,
|
|
1760
|
+
showDefaultLanguage,
|
|
1761
|
+
strapi: strapi2
|
|
1762
|
+
});
|
|
1763
|
+
}
|
|
1713
1764
|
}
|
|
1714
1765
|
delete document.createdBy;
|
|
1715
1766
|
delete document.updatedBy;
|
|
@@ -1727,22 +1778,23 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1727
1778
|
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1728
1779
|
where: {
|
|
1729
1780
|
module: "slug",
|
|
1730
|
-
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel"]
|
|
1781
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1731
1782
|
}
|
|
1732
1783
|
});
|
|
1733
1784
|
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1734
1785
|
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1735
|
-
settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1786
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1787
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1736
1788
|
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1737
1789
|
where: {
|
|
1738
1790
|
state: "published"
|
|
1739
1791
|
}
|
|
1740
1792
|
});
|
|
1741
1793
|
pages.forEach((page) => {
|
|
1742
|
-
if (homepageContentId === page.contentId && defaultLocale === page.locale) {
|
|
1794
|
+
if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale === page.locale) {
|
|
1743
1795
|
page.fullSlug = "";
|
|
1744
|
-
} else if (homepageContentId === page.contentId && defaultLocale !== page.locale) {
|
|
1745
|
-
page.fullSlug = page.locale;
|
|
1796
|
+
} else if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale !== page.locale && homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
1797
|
+
page.fullSlug = page.locale.toLowerCase();
|
|
1746
1798
|
} else {
|
|
1747
1799
|
page.fullSlug = buildFullSlug({ pages, page, defaultLocale, showDefaultLanguage });
|
|
1748
1800
|
}
|
|
@@ -1771,13 +1823,37 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1771
1823
|
}
|
|
1772
1824
|
}
|
|
1773
1825
|
const mappedPages = pages.map((page) => ({
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
locale: page.locale,
|
|
1778
|
-
...page.attributes ? { attributes: page.attributes } : {}
|
|
1826
|
+
...page,
|
|
1827
|
+
...page.attributes ? { attributes: page.attributes } : {},
|
|
1828
|
+
localizations: []
|
|
1779
1829
|
}));
|
|
1780
|
-
|
|
1830
|
+
const rootItems = mappedPages.filter((item) => item.locale === defaultLocale);
|
|
1831
|
+
const mappedItems = rootItems.map((rootItem) => {
|
|
1832
|
+
const relatedItems = mappedPages.filter(
|
|
1833
|
+
(item) => item.contentId === rootItem.contentId && item.contentModel === rootItem.contentModel && item.locale !== defaultLocale
|
|
1834
|
+
);
|
|
1835
|
+
return {
|
|
1836
|
+
id: rootItem.id,
|
|
1837
|
+
documentId: rootItem.contentId,
|
|
1838
|
+
slug: rootItem.fullSlug,
|
|
1839
|
+
locale: rootItem.locale,
|
|
1840
|
+
createdAt: rootItem.updatedAt,
|
|
1841
|
+
updatedAt: rootItem.updatedAt,
|
|
1842
|
+
publishedAt: rootItem.updatedAt,
|
|
1843
|
+
...rootItem.attributes ? { attributes: rootItem.attributes } : {},
|
|
1844
|
+
localizations: relatedItems.map((item) => ({
|
|
1845
|
+
id: item.id,
|
|
1846
|
+
documentId: item.contentId,
|
|
1847
|
+
slug: item.fullSlug,
|
|
1848
|
+
locale: item.locale,
|
|
1849
|
+
createdAt: item.updatedAt,
|
|
1850
|
+
updatedAt: item.updatedAt,
|
|
1851
|
+
publishedAt: item.updatedAt,
|
|
1852
|
+
...item.attributes ? { attributes: item.attributes } : {}
|
|
1853
|
+
}))
|
|
1854
|
+
};
|
|
1855
|
+
});
|
|
1856
|
+
return mappedItems;
|
|
1781
1857
|
},
|
|
1782
1858
|
async getHomePage() {
|
|
1783
1859
|
const ctx = strapi2.requestContext.get();
|
|
@@ -1786,16 +1862,19 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1786
1862
|
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1787
1863
|
where: {
|
|
1788
1864
|
module: "slug",
|
|
1789
|
-
property: ["homepageContentId", "homepageContentModel"]
|
|
1865
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1790
1866
|
}
|
|
1791
1867
|
});
|
|
1868
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1792
1869
|
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1793
1870
|
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1871
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1794
1872
|
const page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
1795
1873
|
where: {
|
|
1796
1874
|
state: "published",
|
|
1797
1875
|
contentId: homepageContentId,
|
|
1798
|
-
contentModel: homepageContentModel
|
|
1876
|
+
contentModel: homepageContentModel,
|
|
1877
|
+
locale: defaultLocale
|
|
1799
1878
|
}
|
|
1800
1879
|
});
|
|
1801
1880
|
if (!page) {
|
|
@@ -1831,11 +1910,21 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1831
1910
|
documentId: page.contentId
|
|
1832
1911
|
});
|
|
1833
1912
|
for (const localization of document.localizations) {
|
|
1834
|
-
|
|
1913
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
1914
|
+
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
1915
|
+
} else {
|
|
1916
|
+
localization.slug = await getSlugByDocumentId({
|
|
1917
|
+
contentId: localization.documentId,
|
|
1918
|
+
locale: localization.locale,
|
|
1919
|
+
defaultLocale,
|
|
1920
|
+
showDefaultLanguage,
|
|
1921
|
+
strapi: strapi2
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1835
1924
|
}
|
|
1836
1925
|
delete document.createdBy;
|
|
1837
1926
|
delete document.updatedBy;
|
|
1838
|
-
document.slug =
|
|
1927
|
+
document.slug = "";
|
|
1839
1928
|
return {
|
|
1840
1929
|
document,
|
|
1841
1930
|
...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: {
|
|
@@ -58,5 +58,13 @@ declare const _default: {
|
|
|
58
58
|
adminBulkDelete(): Promise<any>;
|
|
59
59
|
getTranslations(): Promise<any>;
|
|
60
60
|
};
|
|
61
|
+
LocalesModuleController: ({ strapi }: {
|
|
62
|
+
strapi: import("@strapi/types/dist/core").Strapi;
|
|
63
|
+
}) => {
|
|
64
|
+
getLocales(): Promise<{
|
|
65
|
+
locales: any;
|
|
66
|
+
default: any;
|
|
67
|
+
}>;
|
|
68
|
+
};
|
|
61
69
|
};
|
|
62
70
|
export default _default;
|
|
@@ -99,6 +99,14 @@ declare const _default: {
|
|
|
99
99
|
adminBulkDelete(): Promise<any>;
|
|
100
100
|
getTranslations(): Promise<any>;
|
|
101
101
|
};
|
|
102
|
+
LocalesModuleController: ({ strapi }: {
|
|
103
|
+
strapi: import("@strapi/types/dist/core").Strapi;
|
|
104
|
+
}) => {
|
|
105
|
+
getLocales(): Promise<{
|
|
106
|
+
locales: any;
|
|
107
|
+
default: any;
|
|
108
|
+
}>;
|
|
109
|
+
};
|
|
102
110
|
};
|
|
103
111
|
routes: {
|
|
104
112
|
admin: {
|
|
@@ -145,13 +153,7 @@ declare const _default: {
|
|
|
145
153
|
attributes?: any;
|
|
146
154
|
document: import("@strapi/types/dist/modules/documents").AnyDocument;
|
|
147
155
|
}>;
|
|
148
|
-
getPages(): Promise<
|
|
149
|
-
attributes?: any;
|
|
150
|
-
id: any;
|
|
151
|
-
model: any;
|
|
152
|
-
slug: any;
|
|
153
|
-
locale: any;
|
|
154
|
-
}[]>;
|
|
156
|
+
getPages(): Promise<any[]>;
|
|
155
157
|
getHomePage(): Promise<{
|
|
156
158
|
attributes?: any;
|
|
157
159
|
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