@littlebox/strapi-suite 1.0.33 → 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 +154 -33
- package/dist/_chunks/{App-CXitaGLI.mjs → App-2SwRpCFC.mjs} +214 -27
- package/dist/_chunks/{App-BwtvAoMl.js → App-DBXgA-D1.js} +213 -26
- package/dist/_chunks/{SlugInput-DvuzCwKx.mjs → SlugInput-BcUe-oCY.mjs} +2 -2
- package/dist/_chunks/{SlugInput-0Vo-U5cA.js → SlugInput-CVnNz0al.js} +2 -2
- package/dist/_chunks/{convertToSlug-DGSdTBaK.js → convertToSlug-Btfca6aI.js} +1 -1
- package/dist/_chunks/{convertToSlug-CRnBMJHB.mjs → convertToSlug-q9_W-VMA.mjs} +1 -1
- package/dist/_chunks/{en-Bz6GsXYT.js → en-CGJcJfk1.js} +6 -0
- package/dist/_chunks/{en-RUOaam8y.mjs → en-CRSiVe4w.mjs} +6 -0
- package/dist/_chunks/{index-BBTYu57z.mjs → index-DmkEUACh.mjs} +10 -6
- package/dist/_chunks/{index-BZqSioMv.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/components/SlugSettingsModal.d.ts +7 -1
- package/dist/admin/src/core/config.d.ts +2 -0
- package/dist/server/index.js +199 -31
- package/dist/server/index.mjs +199 -31
- package/dist/server/src/config/index.d.ts +2 -0
- package/dist/server/src/controllers/index.d.ts +1 -0
- package/dist/server/src/controllers/modules/slug.d.ts +1 -0
- package/dist/server/src/index.d.ts +5 -6
- package/dist/server/src/services/index.d.ts +4 -6
- package/dist/server/src/services/modules/slug.d.ts +4 -6
- package/package.json +1 -1
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,
|
|
@@ -394,8 +395,8 @@ async function deleteAttributes(event, config2) {
|
|
|
394
395
|
await strapi.db.query(config2.uuid.modules.attribute).updateMany(updateManyWhere);
|
|
395
396
|
}
|
|
396
397
|
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
398
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
397
399
|
try {
|
|
398
|
-
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
399
400
|
await strapi2.db.query(config2.uuid.app.setting).createMany({
|
|
400
401
|
data: [
|
|
401
402
|
{
|
|
@@ -445,7 +446,31 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
445
446
|
} catch (e) {
|
|
446
447
|
}
|
|
447
448
|
try {
|
|
448
|
-
|
|
449
|
+
await strapi2.db.query(config2.uuid.app.setting).createMany({
|
|
450
|
+
data: [
|
|
451
|
+
{
|
|
452
|
+
module: "slug",
|
|
453
|
+
property: "homepageContentId",
|
|
454
|
+
type: "string",
|
|
455
|
+
value: null
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
module: "slug",
|
|
459
|
+
property: "homepageContentModel",
|
|
460
|
+
type: "string",
|
|
461
|
+
value: null
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
module: "slug",
|
|
465
|
+
property: "homepageSlugStrategy",
|
|
466
|
+
type: "string",
|
|
467
|
+
value: "language"
|
|
468
|
+
}
|
|
469
|
+
]
|
|
470
|
+
});
|
|
471
|
+
} catch (e) {
|
|
472
|
+
}
|
|
473
|
+
try {
|
|
449
474
|
await strapi2.db.query(config2.uuid.modules.template).createMany({
|
|
450
475
|
data: [
|
|
451
476
|
{
|
|
@@ -1088,6 +1113,9 @@ const SlugModuleController = ({ strapi: strapi2 }) => ({
|
|
|
1088
1113
|
const ctx = strapi2.requestContext.get();
|
|
1089
1114
|
const service = strapi2.plugin(PLUGIN_ID).service("SlugModuleService");
|
|
1090
1115
|
return ctx.query.slug ? await service.getPage() : await service.getPages();
|
|
1116
|
+
},
|
|
1117
|
+
async getHomePage() {
|
|
1118
|
+
return await strapi2.plugin(PLUGIN_ID).service("SlugModuleService").getHomePage();
|
|
1091
1119
|
}
|
|
1092
1120
|
});
|
|
1093
1121
|
const AttributeModuleController = ({ strapi: strapi2 }) => ({
|
|
@@ -1241,6 +1269,16 @@ const contentAPIRoutes = [
|
|
|
1241
1269
|
auth: false
|
|
1242
1270
|
}
|
|
1243
1271
|
},
|
|
1272
|
+
{
|
|
1273
|
+
method: "GET",
|
|
1274
|
+
path: "/modules/pages/home",
|
|
1275
|
+
handler: "SlugModuleController.getHomePage",
|
|
1276
|
+
config: {
|
|
1277
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1278
|
+
policies: ["check-api-token"],
|
|
1279
|
+
auth: false
|
|
1280
|
+
}
|
|
1281
|
+
},
|
|
1244
1282
|
{
|
|
1245
1283
|
method: "GET",
|
|
1246
1284
|
path: "/modules/menus",
|
|
@@ -1622,24 +1660,42 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1622
1660
|
const ctx = strapi2.requestContext.get();
|
|
1623
1661
|
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1624
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());
|
|
1625
1665
|
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1626
|
-
const
|
|
1666
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1627
1667
|
where: {
|
|
1628
1668
|
module: "slug",
|
|
1629
|
-
property: "showDefaultLanguage"
|
|
1630
|
-
}
|
|
1631
|
-
});
|
|
1632
|
-
const showDefaultLanguage = setting.value === "true";
|
|
1633
|
-
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1634
|
-
where: {
|
|
1635
|
-
state: "published",
|
|
1636
|
-
slug: slug.split("/")
|
|
1669
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1637
1670
|
}
|
|
1638
1671
|
});
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
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
|
+
}
|
|
1643
1699
|
if (!page) {
|
|
1644
1700
|
ctx.status = 404;
|
|
1645
1701
|
return;
|
|
@@ -1673,13 +1729,17 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1673
1729
|
documentId: page.contentId
|
|
1674
1730
|
});
|
|
1675
1731
|
for (const localization of document.localizations) {
|
|
1676
|
-
localization.
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
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
|
+
}
|
|
1683
1743
|
}
|
|
1684
1744
|
delete document.createdBy;
|
|
1685
1745
|
delete document.updatedBy;
|
|
@@ -1694,20 +1754,29 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1694
1754
|
const properties = ctx.query.properties;
|
|
1695
1755
|
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1696
1756
|
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1697
|
-
const
|
|
1757
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1698
1758
|
where: {
|
|
1699
1759
|
module: "slug",
|
|
1700
|
-
property: "showDefaultLanguage"
|
|
1760
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1701
1761
|
}
|
|
1702
1762
|
});
|
|
1703
|
-
const showDefaultLanguage = setting.value === "true";
|
|
1763
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1764
|
+
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1765
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1766
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1704
1767
|
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1705
1768
|
where: {
|
|
1706
1769
|
state: "published"
|
|
1707
1770
|
}
|
|
1708
1771
|
});
|
|
1709
1772
|
pages.forEach((page) => {
|
|
1710
|
-
page.
|
|
1773
|
+
if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale === page.locale) {
|
|
1774
|
+
page.fullSlug = "";
|
|
1775
|
+
} else if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale !== page.locale && homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
1776
|
+
page.fullSlug = page.locale.toLowerCase();
|
|
1777
|
+
} else {
|
|
1778
|
+
page.fullSlug = buildFullSlug({ pages, page, defaultLocale, showDefaultLanguage });
|
|
1779
|
+
}
|
|
1711
1780
|
});
|
|
1712
1781
|
if (properties && properties.includes("attributes")) {
|
|
1713
1782
|
for (const page of pages) {
|
|
@@ -1733,13 +1802,112 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1733
1802
|
}
|
|
1734
1803
|
}
|
|
1735
1804
|
const mappedPages = pages.map((page) => ({
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1805
|
+
...page,
|
|
1806
|
+
...page.attributes ? { attributes: page.attributes } : {},
|
|
1807
|
+
localizations: []
|
|
1808
|
+
}));
|
|
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;
|
|
1836
|
+
},
|
|
1837
|
+
async getHomePage() {
|
|
1838
|
+
const ctx = strapi2.requestContext.get();
|
|
1839
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1840
|
+
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1841
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1842
|
+
where: {
|
|
1843
|
+
module: "slug",
|
|
1844
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1845
|
+
}
|
|
1846
|
+
});
|
|
1847
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1848
|
+
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1849
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1850
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1851
|
+
const page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
1852
|
+
where: {
|
|
1853
|
+
state: "published",
|
|
1854
|
+
contentId: homepageContentId,
|
|
1855
|
+
contentModel: homepageContentModel,
|
|
1856
|
+
locale: defaultLocale
|
|
1857
|
+
}
|
|
1858
|
+
});
|
|
1859
|
+
if (!page) {
|
|
1860
|
+
ctx.status = 404;
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
const properties = ctx.query.properties;
|
|
1864
|
+
if (properties && properties.includes("attributes")) {
|
|
1865
|
+
const attributes2 = await strapi2.db.query(config2.uuid.modules.attribute).findOne({
|
|
1866
|
+
where: {
|
|
1867
|
+
locale: page.locale,
|
|
1868
|
+
contentId: page.contentId,
|
|
1869
|
+
contentModel: page.contentModel,
|
|
1870
|
+
state: "published"
|
|
1871
|
+
}
|
|
1872
|
+
});
|
|
1873
|
+
const template = attributes2 && attributes2.templateId ? await strapi2.db.query(config2.uuid.modules.template).findOne({
|
|
1874
|
+
where: {
|
|
1875
|
+
documentId: attributes2.templateId
|
|
1876
|
+
}
|
|
1877
|
+
}) : null;
|
|
1878
|
+
page.attributes = {
|
|
1879
|
+
template: template?.uid || "default",
|
|
1880
|
+
priority: attributes2?.priority || "0.5",
|
|
1881
|
+
frequency: attributes2?.frequency || "weekly",
|
|
1882
|
+
...attributes2?.parentContentId ? { parent: { id: attributes2.parentContentId, model: attributes2.parentContentModel } } : {}
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
const document = await strapi2.documents(page.contentModel).findOne({
|
|
1739
1886
|
locale: page.locale,
|
|
1887
|
+
populate: "*",
|
|
1888
|
+
status: "published",
|
|
1889
|
+
documentId: page.contentId
|
|
1890
|
+
});
|
|
1891
|
+
for (const localization of document.localizations) {
|
|
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
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
delete document.createdBy;
|
|
1905
|
+
delete document.updatedBy;
|
|
1906
|
+
document.slug = "";
|
|
1907
|
+
return {
|
|
1908
|
+
document,
|
|
1740
1909
|
...page.attributes ? { attributes: page.attributes } : {}
|
|
1741
|
-
}
|
|
1742
|
-
return mappedPages;
|
|
1910
|
+
};
|
|
1743
1911
|
}
|
|
1744
1912
|
});
|
|
1745
1913
|
async function fetchAdditionalData(params) {
|
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,
|
|
@@ -393,8 +394,8 @@ async function deleteAttributes(event, config2) {
|
|
|
393
394
|
await strapi.db.query(config2.uuid.modules.attribute).updateMany(updateManyWhere);
|
|
394
395
|
}
|
|
395
396
|
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
397
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
396
398
|
try {
|
|
397
|
-
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
398
399
|
await strapi2.db.query(config2.uuid.app.setting).createMany({
|
|
399
400
|
data: [
|
|
400
401
|
{
|
|
@@ -444,7 +445,31 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
444
445
|
} catch (e) {
|
|
445
446
|
}
|
|
446
447
|
try {
|
|
447
|
-
|
|
448
|
+
await strapi2.db.query(config2.uuid.app.setting).createMany({
|
|
449
|
+
data: [
|
|
450
|
+
{
|
|
451
|
+
module: "slug",
|
|
452
|
+
property: "homepageContentId",
|
|
453
|
+
type: "string",
|
|
454
|
+
value: null
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
module: "slug",
|
|
458
|
+
property: "homepageContentModel",
|
|
459
|
+
type: "string",
|
|
460
|
+
value: null
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
module: "slug",
|
|
464
|
+
property: "homepageSlugStrategy",
|
|
465
|
+
type: "string",
|
|
466
|
+
value: "language"
|
|
467
|
+
}
|
|
468
|
+
]
|
|
469
|
+
});
|
|
470
|
+
} catch (e) {
|
|
471
|
+
}
|
|
472
|
+
try {
|
|
448
473
|
await strapi2.db.query(config2.uuid.modules.template).createMany({
|
|
449
474
|
data: [
|
|
450
475
|
{
|
|
@@ -1087,6 +1112,9 @@ const SlugModuleController = ({ strapi: strapi2 }) => ({
|
|
|
1087
1112
|
const ctx = strapi2.requestContext.get();
|
|
1088
1113
|
const service = strapi2.plugin(PLUGIN_ID).service("SlugModuleService");
|
|
1089
1114
|
return ctx.query.slug ? await service.getPage() : await service.getPages();
|
|
1115
|
+
},
|
|
1116
|
+
async getHomePage() {
|
|
1117
|
+
return await strapi2.plugin(PLUGIN_ID).service("SlugModuleService").getHomePage();
|
|
1090
1118
|
}
|
|
1091
1119
|
});
|
|
1092
1120
|
const AttributeModuleController = ({ strapi: strapi2 }) => ({
|
|
@@ -1240,6 +1268,16 @@ const contentAPIRoutes = [
|
|
|
1240
1268
|
auth: false
|
|
1241
1269
|
}
|
|
1242
1270
|
},
|
|
1271
|
+
{
|
|
1272
|
+
method: "GET",
|
|
1273
|
+
path: "/modules/pages/home",
|
|
1274
|
+
handler: "SlugModuleController.getHomePage",
|
|
1275
|
+
config: {
|
|
1276
|
+
middlewares: [`plugin::${PLUGIN_ID}.check-module-is-active`],
|
|
1277
|
+
policies: ["check-api-token"],
|
|
1278
|
+
auth: false
|
|
1279
|
+
}
|
|
1280
|
+
},
|
|
1243
1281
|
{
|
|
1244
1282
|
method: "GET",
|
|
1245
1283
|
path: "/modules/menus",
|
|
@@ -1621,24 +1659,42 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1621
1659
|
const ctx = strapi2.requestContext.get();
|
|
1622
1660
|
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1623
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());
|
|
1624
1664
|
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1625
|
-
const
|
|
1665
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1626
1666
|
where: {
|
|
1627
1667
|
module: "slug",
|
|
1628
|
-
property: "showDefaultLanguage"
|
|
1629
|
-
}
|
|
1630
|
-
});
|
|
1631
|
-
const showDefaultLanguage = setting.value === "true";
|
|
1632
|
-
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1633
|
-
where: {
|
|
1634
|
-
state: "published",
|
|
1635
|
-
slug: slug.split("/")
|
|
1668
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1636
1669
|
}
|
|
1637
1670
|
});
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
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
|
+
}
|
|
1642
1698
|
if (!page) {
|
|
1643
1699
|
ctx.status = 404;
|
|
1644
1700
|
return;
|
|
@@ -1672,13 +1728,17 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1672
1728
|
documentId: page.contentId
|
|
1673
1729
|
});
|
|
1674
1730
|
for (const localization of document.localizations) {
|
|
1675
|
-
localization.
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
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
|
+
}
|
|
1682
1742
|
}
|
|
1683
1743
|
delete document.createdBy;
|
|
1684
1744
|
delete document.updatedBy;
|
|
@@ -1693,20 +1753,29 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1693
1753
|
const properties = ctx.query.properties;
|
|
1694
1754
|
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1695
1755
|
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1696
|
-
const
|
|
1756
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1697
1757
|
where: {
|
|
1698
1758
|
module: "slug",
|
|
1699
|
-
property: "showDefaultLanguage"
|
|
1759
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1700
1760
|
}
|
|
1701
1761
|
});
|
|
1702
|
-
const showDefaultLanguage = setting.value === "true";
|
|
1762
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1763
|
+
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1764
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1765
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1703
1766
|
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1704
1767
|
where: {
|
|
1705
1768
|
state: "published"
|
|
1706
1769
|
}
|
|
1707
1770
|
});
|
|
1708
1771
|
pages.forEach((page) => {
|
|
1709
|
-
page.
|
|
1772
|
+
if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale === page.locale) {
|
|
1773
|
+
page.fullSlug = "";
|
|
1774
|
+
} else if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale !== page.locale && homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
1775
|
+
page.fullSlug = page.locale.toLowerCase();
|
|
1776
|
+
} else {
|
|
1777
|
+
page.fullSlug = buildFullSlug({ pages, page, defaultLocale, showDefaultLanguage });
|
|
1778
|
+
}
|
|
1710
1779
|
});
|
|
1711
1780
|
if (properties && properties.includes("attributes")) {
|
|
1712
1781
|
for (const page of pages) {
|
|
@@ -1732,13 +1801,112 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1732
1801
|
}
|
|
1733
1802
|
}
|
|
1734
1803
|
const mappedPages = pages.map((page) => ({
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1804
|
+
...page,
|
|
1805
|
+
...page.attributes ? { attributes: page.attributes } : {},
|
|
1806
|
+
localizations: []
|
|
1807
|
+
}));
|
|
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;
|
|
1835
|
+
},
|
|
1836
|
+
async getHomePage() {
|
|
1837
|
+
const ctx = strapi2.requestContext.get();
|
|
1838
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1839
|
+
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1840
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1841
|
+
where: {
|
|
1842
|
+
module: "slug",
|
|
1843
|
+
property: ["showDefaultLanguage", "homepageContentId", "homepageContentModel", "homepageSlugStrategy"]
|
|
1844
|
+
}
|
|
1845
|
+
});
|
|
1846
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1847
|
+
const homepageContentId = settings.find((setting) => setting.property === "homepageContentId").value;
|
|
1848
|
+
const homepageContentModel = settings.find((setting) => setting.property === "homepageContentModel").value;
|
|
1849
|
+
const homepageSlugStrategy = settings.find((setting) => setting.property === "homepageSlugStrategy").value;
|
|
1850
|
+
const page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
1851
|
+
where: {
|
|
1852
|
+
state: "published",
|
|
1853
|
+
contentId: homepageContentId,
|
|
1854
|
+
contentModel: homepageContentModel,
|
|
1855
|
+
locale: defaultLocale
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
if (!page) {
|
|
1859
|
+
ctx.status = 404;
|
|
1860
|
+
return;
|
|
1861
|
+
}
|
|
1862
|
+
const properties = ctx.query.properties;
|
|
1863
|
+
if (properties && properties.includes("attributes")) {
|
|
1864
|
+
const attributes2 = await strapi2.db.query(config2.uuid.modules.attribute).findOne({
|
|
1865
|
+
where: {
|
|
1866
|
+
locale: page.locale,
|
|
1867
|
+
contentId: page.contentId,
|
|
1868
|
+
contentModel: page.contentModel,
|
|
1869
|
+
state: "published"
|
|
1870
|
+
}
|
|
1871
|
+
});
|
|
1872
|
+
const template = attributes2 && attributes2.templateId ? await strapi2.db.query(config2.uuid.modules.template).findOne({
|
|
1873
|
+
where: {
|
|
1874
|
+
documentId: attributes2.templateId
|
|
1875
|
+
}
|
|
1876
|
+
}) : null;
|
|
1877
|
+
page.attributes = {
|
|
1878
|
+
template: template?.uid || "default",
|
|
1879
|
+
priority: attributes2?.priority || "0.5",
|
|
1880
|
+
frequency: attributes2?.frequency || "weekly",
|
|
1881
|
+
...attributes2?.parentContentId ? { parent: { id: attributes2.parentContentId, model: attributes2.parentContentModel } } : {}
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
const document = await strapi2.documents(page.contentModel).findOne({
|
|
1738
1885
|
locale: page.locale,
|
|
1886
|
+
populate: "*",
|
|
1887
|
+
status: "published",
|
|
1888
|
+
documentId: page.contentId
|
|
1889
|
+
});
|
|
1890
|
+
for (const localization of document.localizations) {
|
|
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
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
delete document.createdBy;
|
|
1904
|
+
delete document.updatedBy;
|
|
1905
|
+
document.slug = "";
|
|
1906
|
+
return {
|
|
1907
|
+
document,
|
|
1739
1908
|
...page.attributes ? { attributes: page.attributes } : {}
|
|
1740
|
-
}
|
|
1741
|
-
return mappedPages;
|
|
1909
|
+
};
|
|
1742
1910
|
}
|
|
1743
1911
|
});
|
|
1744
1912
|
async function fetchAdditionalData(params) {
|
|
@@ -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: {
|
|
@@ -47,6 +47,7 @@ declare const _default: {
|
|
|
47
47
|
adminGetAll(): Promise<any>;
|
|
48
48
|
adminBulkDelete(): Promise<any>;
|
|
49
49
|
getPages(): Promise<any>;
|
|
50
|
+
getHomePage(): Promise<any>;
|
|
50
51
|
};
|
|
51
52
|
AttributeModuleController: ({ strapi }: {
|
|
52
53
|
/**
|
|
@@ -144,13 +145,11 @@ declare const _default: {
|
|
|
144
145
|
attributes?: any;
|
|
145
146
|
document: import("@strapi/types/dist/modules/documents").AnyDocument;
|
|
146
147
|
}>;
|
|
147
|
-
getPages(): Promise<
|
|
148
|
+
getPages(): Promise<any[]>;
|
|
149
|
+
getHomePage(): Promise<{
|
|
148
150
|
attributes?: any;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
slug: any;
|
|
152
|
-
locale: any;
|
|
153
|
-
}[]>;
|
|
151
|
+
document: import("@strapi/types/dist/modules/documents").AnyDocument;
|
|
152
|
+
}>;
|
|
154
153
|
};
|
|
155
154
|
AttributeModuleService: ({ strapi }: {
|
|
156
155
|
strapi: import("@strapi/types/dist/core").Strapi;
|