@littlebox/strapi-suite 1.0.52 → 1.0.54
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 +29 -0
- package/dist/_chunks/{App-C-h--Kv_.js → App-B7_8BaVG.js} +2 -2
- package/dist/_chunks/{App-C1HyspTk.mjs → App-BfGB2pF_.mjs} +2 -2
- package/dist/_chunks/{SlugInput-CU9_b0dd.mjs → SlugInput-CvgVtZza.mjs} +1 -1
- package/dist/_chunks/{SlugInput-3gkr6B0t.js → SlugInput-eCwgqJtH.js} +1 -1
- package/dist/_chunks/{en-CLNZnNeq.js → en-D89cXiov.js} +16 -1
- package/dist/_chunks/{en-F6RYx79c.mjs → en-knG97mCH.mjs} +16 -1
- package/dist/_chunks/{index-DQ3vX9So.mjs → index-97f0S4q6.mjs} +1632 -65
- package/dist/_chunks/{index-60sq8G6p.js → index-DnXsi_Ar.js} +1629 -62
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/core/utils/tabs.d.ts +53 -0
- package/dist/admin/src/ctb/TabSelect.d.ts +31 -0
- package/dist/admin/src/ctb/TabsEditor.d.ts +21 -0
- package/dist/admin/src/ctb/registerTabsInContentTypeBuilder.d.ts +1 -0
- package/dist/admin/src/ctb/tabBadges.d.ts +14 -0
- package/dist/admin/src/editView/TabSection.d.ts +6 -0
- package/dist/admin/src/editView/TabsBar.d.ts +10 -0
- package/dist/admin/src/editView/mutateEditViewLayout.d.ts +12 -0
- package/dist/admin/src/editView/sectionVisibility.d.ts +7 -0
- package/dist/admin/src/editView/tabsStore.d.ts +13 -0
- package/dist/server/index.js +426 -313
- package/dist/server/index.mjs +426 -313
- package/dist/server/src/middlewares/tabs.d.ts +4 -0
- package/dist/server/src/utils/groupByContentTypeTabs.d.ts +7 -0
- package/dist/server/src/utils/tabs.d.ts +17 -0
- package/package.json +6 -3
package/dist/server/index.js
CHANGED
|
@@ -543,12 +543,122 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
543
543
|
};
|
|
544
544
|
const destroy = ({ strapi: strapi2 }) => {
|
|
545
545
|
};
|
|
546
|
+
const TABS_PLUGIN_KEY = "littlebox-strapi-suite";
|
|
547
|
+
const SYSTEM_KEYS = [
|
|
548
|
+
"id",
|
|
549
|
+
"documentId",
|
|
550
|
+
"locale",
|
|
551
|
+
"createdAt",
|
|
552
|
+
"updatedAt",
|
|
553
|
+
"publishedAt",
|
|
554
|
+
"createdBy",
|
|
555
|
+
"updatedBy",
|
|
556
|
+
"localizations"
|
|
557
|
+
];
|
|
558
|
+
function toTabKey(name) {
|
|
559
|
+
return (name ?? "").normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/\s+/g, "_").replace(/[^a-z0-9_]/g, "").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
560
|
+
}
|
|
561
|
+
function readTabs(pluginOptions2) {
|
|
562
|
+
const tabs = pluginOptions2?.[TABS_PLUGIN_KEY]?.tabs;
|
|
563
|
+
if (!Array.isArray(tabs)) return [];
|
|
564
|
+
return tabs.filter((tab) => tab && typeof tab.id === "string" && typeof tab.name === "string");
|
|
565
|
+
}
|
|
566
|
+
function readAttributeTabId(attribute) {
|
|
567
|
+
const id = attribute?.pluginOptions?.[TABS_PLUGIN_KEY]?.tab;
|
|
568
|
+
return typeof id === "string" && id !== "" ? id : null;
|
|
569
|
+
}
|
|
570
|
+
function buildTabGroups(tabs, attributes2, onConflict) {
|
|
571
|
+
const candidates = tabs.map((tab) => ({
|
|
572
|
+
tab,
|
|
573
|
+
key: toTabKey(tab.name),
|
|
574
|
+
fields: Object.entries(attributes2).filter(([, attribute]) => readAttributeTabId(attribute) === tab.id).map(([name]) => name)
|
|
575
|
+
})).filter((group) => group.fields.length > 0);
|
|
576
|
+
const reservedKeys = /* @__PURE__ */ new Set([...SYSTEM_KEYS, ...Object.keys(attributes2)]);
|
|
577
|
+
const usedKeys = /* @__PURE__ */ new Set();
|
|
578
|
+
return candidates.filter((group) => {
|
|
579
|
+
if (group.key === "" || reservedKeys.has(group.key) || usedKeys.has(group.key)) {
|
|
580
|
+
onConflict?.(group.tab, group.key);
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
usedKeys.add(group.key);
|
|
584
|
+
return true;
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
function groupEntryByTabs(entry, groups) {
|
|
588
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry) || groups.length === 0) {
|
|
589
|
+
return entry;
|
|
590
|
+
}
|
|
591
|
+
const fieldToKey = /* @__PURE__ */ new Map();
|
|
592
|
+
groups.forEach((group) => group.fields.forEach((field) => fieldToKey.set(field, group.key)));
|
|
593
|
+
const result = {};
|
|
594
|
+
const grouped = {};
|
|
595
|
+
Object.entries(entry).forEach(([name, value]) => {
|
|
596
|
+
const key = fieldToKey.get(name);
|
|
597
|
+
if (key === void 0) {
|
|
598
|
+
result[name] = value;
|
|
599
|
+
} else {
|
|
600
|
+
(grouped[key] ??= {})[name] = value;
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
groups.forEach((group) => {
|
|
604
|
+
if (grouped[group.key]) result[group.key] = grouped[group.key];
|
|
605
|
+
});
|
|
606
|
+
return result;
|
|
607
|
+
}
|
|
608
|
+
function groupDataByTabs(data, groups) {
|
|
609
|
+
if (groups.length === 0) return data;
|
|
610
|
+
return Array.isArray(data) ? data.map((entry) => groupEntryByTabs(entry, groups)) : groupEntryByTabs(data, groups);
|
|
611
|
+
}
|
|
612
|
+
function parseHandlerUid(handler) {
|
|
613
|
+
if (typeof handler !== "string") return null;
|
|
614
|
+
const match = handler.match(/^(.+)\.(find|findOne)$/);
|
|
615
|
+
return match ? match[1] : null;
|
|
616
|
+
}
|
|
617
|
+
function createContentTypeTabsGrouper(strapi2) {
|
|
618
|
+
const warned = /* @__PURE__ */ new Set();
|
|
619
|
+
return function groupByContentTypeTabs(uid, data) {
|
|
620
|
+
try {
|
|
621
|
+
const contentType = strapi2.contentType(uid);
|
|
622
|
+
if (!contentType) return data;
|
|
623
|
+
const tabs = readTabs(contentType.pluginOptions);
|
|
624
|
+
if (tabs.length === 0) return data;
|
|
625
|
+
const groups = buildTabGroups(tabs, contentType.attributes ?? {}, (tab, key) => {
|
|
626
|
+
const id = `${uid}:${tab.id}`;
|
|
627
|
+
if (warned.has(id)) return;
|
|
628
|
+
warned.add(id);
|
|
629
|
+
strapi2.log.warn(
|
|
630
|
+
`[littlebox-strapi-suite] Tab "${tab.name}" of ${uid} was not grouped: the key "${key}" is empty or conflicts with a field or another tab.`
|
|
631
|
+
);
|
|
632
|
+
});
|
|
633
|
+
return groupDataByTabs(data, groups);
|
|
634
|
+
} catch (error) {
|
|
635
|
+
strapi2.log.error(`[littlebox-strapi-suite] Could not group ${uid} data by tabs: ${error}`);
|
|
636
|
+
return data;
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
function createTabsMiddleware({ strapi: strapi2 }) {
|
|
641
|
+
const groupByContentTypeTabs = createContentTypeTabsGrouper(strapi2);
|
|
642
|
+
return async (ctx, next) => {
|
|
643
|
+
await next();
|
|
644
|
+
if (ctx.method !== "GET" || ctx.status !== 200) return;
|
|
645
|
+
const prefix = strapi2.config.get("api.rest.prefix", "/api");
|
|
646
|
+
if (!ctx.path?.startsWith(prefix)) return;
|
|
647
|
+
const body = ctx.body;
|
|
648
|
+
if (!body || typeof body !== "object" || body.data == null) return;
|
|
649
|
+
const uid = parseHandlerUid(ctx.state?.route?.handler);
|
|
650
|
+
if (!uid) return;
|
|
651
|
+
const data = groupByContentTypeTabs(uid, body.data);
|
|
652
|
+
if (data !== body.data) ctx.body = { ...body, data };
|
|
653
|
+
};
|
|
654
|
+
}
|
|
546
655
|
const register = ({ strapi: strapi2 }) => {
|
|
547
656
|
strapi2.customFields.register({
|
|
548
657
|
name: "ltbslug",
|
|
549
658
|
plugin: PLUGIN_ID,
|
|
550
659
|
type: "uid"
|
|
551
660
|
});
|
|
661
|
+
strapi2.server.use(createTabsMiddleware({ strapi: strapi2 }));
|
|
552
662
|
};
|
|
553
663
|
const kind$7 = "collectionType";
|
|
554
664
|
const collectionName$7 = "ltb_st_app_setting";
|
|
@@ -1893,210 +2003,108 @@ async function findDocumentIdsAndFetchSlugs(params) {
|
|
|
1893
2003
|
await Promise.all(promises);
|
|
1894
2004
|
return params.document;
|
|
1895
2005
|
}
|
|
1896
|
-
const SlugModuleService = ({ strapi: strapi2 }) =>
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
state: "published"
|
|
1905
|
-
},
|
|
1906
|
-
orderBy: {
|
|
1907
|
-
id: "desc"
|
|
1908
|
-
}
|
|
1909
|
-
});
|
|
1910
|
-
const publishedResults = [];
|
|
1911
|
-
for (const document of documents) {
|
|
1912
|
-
const content = await strapi2.documents(document.contentModel).findOne({
|
|
1913
|
-
status: "published",
|
|
1914
|
-
documentId: document.contentId,
|
|
1915
|
-
locale: ctx.query.locale
|
|
1916
|
-
});
|
|
1917
|
-
if (content) {
|
|
1918
|
-
document.contentTitle = content.title || `${content.documentId} | ${document.contentModel}`;
|
|
1919
|
-
publishedResults.push(document);
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
return publishedResults || [];
|
|
1923
|
-
},
|
|
1924
|
-
async adminBulkDelete() {
|
|
1925
|
-
const ctx = strapi2.requestContext.get();
|
|
1926
|
-
if (!ctx.query.locale) return;
|
|
1927
|
-
const body = ctx.request.body;
|
|
1928
|
-
if (!body.contentIds) return;
|
|
1929
|
-
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1930
|
-
await strapi2.db.query(config2.uuid.modules.slug).deleteMany({
|
|
1931
|
-
where: {
|
|
1932
|
-
contentId: body.contentIds,
|
|
1933
|
-
locale: ctx.query.locale
|
|
1934
|
-
}
|
|
1935
|
-
});
|
|
1936
|
-
ctx.status = 204;
|
|
1937
|
-
return;
|
|
1938
|
-
},
|
|
1939
|
-
async getPage() {
|
|
1940
|
-
const ctx = strapi2.requestContext.get();
|
|
1941
|
-
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
1942
|
-
const slug = ctx.query.slug.replace(/^\/|\/$/g, "");
|
|
1943
|
-
const locales = await strapi2.plugin("i18n").service("locales").find();
|
|
1944
|
-
const mappedLocales = locales.map((locale) => locale.code.toLowerCase());
|
|
1945
|
-
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
1946
|
-
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1947
|
-
where: {
|
|
1948
|
-
module: "slug",
|
|
1949
|
-
property: [
|
|
1950
|
-
"showDefaultLanguage",
|
|
1951
|
-
"homepageContentId",
|
|
1952
|
-
"homepageContentModel",
|
|
1953
|
-
"homepageSlugStrategy"
|
|
1954
|
-
]
|
|
1955
|
-
}
|
|
1956
|
-
});
|
|
1957
|
-
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
1958
|
-
const homepageContentId = settings.find(
|
|
1959
|
-
(setting) => setting.property === "homepageContentId"
|
|
1960
|
-
).value;
|
|
1961
|
-
const homepageSlugStrategy = settings.find(
|
|
1962
|
-
(setting) => setting.property === "homepageSlugStrategy"
|
|
1963
|
-
).value;
|
|
1964
|
-
const homepageContentModel = settings.find(
|
|
1965
|
-
(setting) => setting.property === "homepageContentModel"
|
|
1966
|
-
).value;
|
|
1967
|
-
let page;
|
|
1968
|
-
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && mappedLocales.includes(slug)) {
|
|
1969
|
-
page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
2006
|
+
const SlugModuleService = ({ strapi: strapi2 }) => {
|
|
2007
|
+
const groupByContentTypeTabs = createContentTypeTabsGrouper(strapi2);
|
|
2008
|
+
return {
|
|
2009
|
+
async adminGetAll() {
|
|
2010
|
+
const ctx = strapi2.requestContext.get();
|
|
2011
|
+
if (!ctx.query.locale) return [];
|
|
2012
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
2013
|
+
const documents = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
1970
2014
|
where: {
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
2015
|
+
locale: ctx.query.locale,
|
|
2016
|
+
state: "published"
|
|
2017
|
+
},
|
|
2018
|
+
orderBy: {
|
|
2019
|
+
id: "desc"
|
|
1975
2020
|
}
|
|
1976
2021
|
});
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2022
|
+
const publishedResults = [];
|
|
2023
|
+
for (const document of documents) {
|
|
2024
|
+
const content = await strapi2.documents(document.contentModel).findOne({
|
|
2025
|
+
status: "published",
|
|
2026
|
+
documentId: document.contentId,
|
|
2027
|
+
locale: ctx.query.locale
|
|
2028
|
+
});
|
|
2029
|
+
if (content) {
|
|
2030
|
+
document.contentTitle = content.title || `${content.documentId} | ${document.contentModel}`;
|
|
2031
|
+
publishedResults.push(document);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
return publishedResults || [];
|
|
2035
|
+
},
|
|
2036
|
+
async adminBulkDelete() {
|
|
2037
|
+
const ctx = strapi2.requestContext.get();
|
|
2038
|
+
if (!ctx.query.locale) return;
|
|
2039
|
+
const body = ctx.request.body;
|
|
2040
|
+
if (!body.contentIds) return;
|
|
2041
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
2042
|
+
await strapi2.db.query(config2.uuid.modules.slug).deleteMany({
|
|
1980
2043
|
where: {
|
|
1981
|
-
|
|
1982
|
-
|
|
2044
|
+
contentId: body.contentIds,
|
|
2045
|
+
locale: ctx.query.locale
|
|
1983
2046
|
}
|
|
1984
2047
|
});
|
|
1985
|
-
|
|
1986
|
-
page2.fullSlug = buildFullSlug({ pages, page: page2, defaultLocale, showDefaultLanguage });
|
|
1987
|
-
});
|
|
1988
|
-
page = pages.find((page2) => page2.fullSlug === slug);
|
|
1989
|
-
}
|
|
1990
|
-
if (!page) {
|
|
1991
|
-
ctx.status = 404;
|
|
2048
|
+
ctx.status = 204;
|
|
1992
2049
|
return;
|
|
1993
|
-
}
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
const
|
|
2050
|
+
},
|
|
2051
|
+
async getPage() {
|
|
2052
|
+
const ctx = strapi2.requestContext.get();
|
|
2053
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
2054
|
+
const slug = ctx.query.slug.replace(/^\/|\/$/g, "");
|
|
2055
|
+
const locales = await strapi2.plugin("i18n").service("locales").find();
|
|
2056
|
+
const mappedLocales = locales.map((locale) => locale.code.toLowerCase());
|
|
2057
|
+
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
2058
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
1997
2059
|
where: {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2060
|
+
module: "slug",
|
|
2061
|
+
property: [
|
|
2062
|
+
"showDefaultLanguage",
|
|
2063
|
+
"homepageContentId",
|
|
2064
|
+
"homepageContentModel",
|
|
2065
|
+
"homepageSlugStrategy"
|
|
2066
|
+
]
|
|
2002
2067
|
}
|
|
2003
2068
|
});
|
|
2004
|
-
const
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
defaultLocale,
|
|
2026
|
-
showDefaultLanguage
|
|
2027
|
-
});
|
|
2028
|
-
for (const localization of document.localizations) {
|
|
2029
|
-
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && localization.documentId === homepageContentId) {
|
|
2030
|
-
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
2069
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
2070
|
+
const homepageContentId = settings.find(
|
|
2071
|
+
(setting) => setting.property === "homepageContentId"
|
|
2072
|
+
).value;
|
|
2073
|
+
const homepageSlugStrategy = settings.find(
|
|
2074
|
+
(setting) => setting.property === "homepageSlugStrategy"
|
|
2075
|
+
).value;
|
|
2076
|
+
const homepageContentModel = settings.find(
|
|
2077
|
+
(setting) => setting.property === "homepageContentModel"
|
|
2078
|
+
).value;
|
|
2079
|
+
let page;
|
|
2080
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && mappedLocales.includes(slug)) {
|
|
2081
|
+
page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
2082
|
+
where: {
|
|
2083
|
+
state: "published",
|
|
2084
|
+
contentId: homepageContentId,
|
|
2085
|
+
contentModel: homepageContentModel,
|
|
2086
|
+
locale: slug
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
page.fullSlug = slug;
|
|
2031
2090
|
} else {
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
strapi: strapi2
|
|
2091
|
+
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
2092
|
+
where: {
|
|
2093
|
+
state: "published",
|
|
2094
|
+
slug: slug.split("/")
|
|
2095
|
+
}
|
|
2038
2096
|
});
|
|
2097
|
+
pages.forEach((page2) => {
|
|
2098
|
+
page2.fullSlug = buildFullSlug({ pages, page: page2, defaultLocale, showDefaultLanguage });
|
|
2099
|
+
});
|
|
2100
|
+
page = pages.find((page2) => page2.fullSlug === slug);
|
|
2039
2101
|
}
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
document.slug = page.fullSlug;
|
|
2044
|
-
document.breadcrumbs = await buildBreadcrumbs({
|
|
2045
|
-
strapi: strapi2,
|
|
2046
|
-
page,
|
|
2047
|
-
defaultLocale,
|
|
2048
|
-
showDefaultLanguage,
|
|
2049
|
-
homepageSlugStrategy,
|
|
2050
|
-
homepageContentId,
|
|
2051
|
-
homepageContentModel
|
|
2052
|
-
});
|
|
2053
|
-
return {
|
|
2054
|
-
document,
|
|
2055
|
-
...page.attributes ? { attributes: page.attributes } : {}
|
|
2056
|
-
};
|
|
2057
|
-
},
|
|
2058
|
-
async getPages() {
|
|
2059
|
-
const ctx = strapi2.requestContext.get();
|
|
2060
|
-
const properties = ctx.query.properties;
|
|
2061
|
-
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
2062
|
-
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
2063
|
-
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
2064
|
-
where: {
|
|
2065
|
-
module: "slug",
|
|
2066
|
-
property: [
|
|
2067
|
-
"showDefaultLanguage",
|
|
2068
|
-
"homepageContentId",
|
|
2069
|
-
"homepageContentModel",
|
|
2070
|
-
"homepageSlugStrategy"
|
|
2071
|
-
]
|
|
2072
|
-
}
|
|
2073
|
-
});
|
|
2074
|
-
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
2075
|
-
const homepageContentId = settings.find(
|
|
2076
|
-
(setting) => setting.property === "homepageContentId"
|
|
2077
|
-
).value;
|
|
2078
|
-
const homepageContentModel = settings.find(
|
|
2079
|
-
(setting) => setting.property === "homepageContentModel"
|
|
2080
|
-
).value;
|
|
2081
|
-
const homepageSlugStrategy = settings.find(
|
|
2082
|
-
(setting) => setting.property === "homepageSlugStrategy"
|
|
2083
|
-
).value;
|
|
2084
|
-
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
2085
|
-
where: {
|
|
2086
|
-
state: "published"
|
|
2087
|
-
}
|
|
2088
|
-
});
|
|
2089
|
-
pages.forEach((page) => {
|
|
2090
|
-
if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale === page.locale) {
|
|
2091
|
-
page.fullSlug = "";
|
|
2092
|
-
} else if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale !== page.locale && homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
2093
|
-
page.fullSlug = page.locale.toLowerCase();
|
|
2094
|
-
} else {
|
|
2095
|
-
page.fullSlug = buildFullSlug({ pages, page, defaultLocale, showDefaultLanguage });
|
|
2102
|
+
if (!page) {
|
|
2103
|
+
ctx.status = 404;
|
|
2104
|
+
return;
|
|
2096
2105
|
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
for (const page of pages) {
|
|
2106
|
+
const properties = ctx.query.properties;
|
|
2107
|
+
if (properties && properties.includes("attributes")) {
|
|
2100
2108
|
const attributes2 = await strapi2.db.query(config2.uuid.modules.attribute).findOne({
|
|
2101
2109
|
where: {
|
|
2102
2110
|
locale: page.locale,
|
|
@@ -2117,140 +2125,245 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
2117
2125
|
...attributes2?.parentContentId ? { parent: { id: attributes2.parentContentId, model: attributes2.parentContentModel } } : {}
|
|
2118
2126
|
};
|
|
2119
2127
|
}
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2128
|
+
const query = populateQueryFromContentType(strapi2, page.contentModel);
|
|
2129
|
+
const document = await strapi2.documents(page.contentModel).findOne({
|
|
2130
|
+
locale: page.locale,
|
|
2131
|
+
populate: query,
|
|
2132
|
+
status: "published",
|
|
2133
|
+
documentId: page.contentId
|
|
2134
|
+
});
|
|
2135
|
+
await findDocumentIdsAndFetchSlugs({
|
|
2136
|
+
document,
|
|
2137
|
+
defaultLocale,
|
|
2138
|
+
showDefaultLanguage
|
|
2139
|
+
});
|
|
2140
|
+
for (const localization of document.localizations) {
|
|
2141
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && localization.documentId === homepageContentId) {
|
|
2142
|
+
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
2143
|
+
} else {
|
|
2144
|
+
localization.slug = await getSlugByDocumentId({
|
|
2145
|
+
contentId: localization.documentId,
|
|
2146
|
+
locale: localization.locale,
|
|
2147
|
+
defaultLocale,
|
|
2148
|
+
showDefaultLanguage,
|
|
2149
|
+
strapi: strapi2
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
delete document.createdBy;
|
|
2154
|
+
delete document.updatedBy;
|
|
2155
|
+
document.slug = page.fullSlug;
|
|
2156
|
+
document.breadcrumbs = await buildBreadcrumbs({
|
|
2157
|
+
strapi: strapi2,
|
|
2158
|
+
page,
|
|
2159
|
+
defaultLocale,
|
|
2160
|
+
showDefaultLanguage,
|
|
2161
|
+
homepageSlugStrategy,
|
|
2162
|
+
homepageContentId,
|
|
2163
|
+
homepageContentModel
|
|
2164
|
+
});
|
|
2131
2165
|
return {
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
slug: rootItem.fullSlug,
|
|
2135
|
-
locale: rootItem.locale,
|
|
2136
|
-
createdAt: rootItem.updatedAt,
|
|
2137
|
-
updatedAt: rootItem.updatedAt,
|
|
2138
|
-
publishedAt: rootItem.updatedAt,
|
|
2139
|
-
...rootItem.attributes ? { attributes: rootItem.attributes } : {},
|
|
2140
|
-
localizations: relatedItems.map((item) => ({
|
|
2141
|
-
id: item.id,
|
|
2142
|
-
documentId: item.contentId,
|
|
2143
|
-
slug: item.fullSlug,
|
|
2144
|
-
locale: item.locale,
|
|
2145
|
-
createdAt: item.updatedAt,
|
|
2146
|
-
updatedAt: item.updatedAt,
|
|
2147
|
-
publishedAt: item.updatedAt,
|
|
2148
|
-
...item.attributes ? { attributes: item.attributes } : {}
|
|
2149
|
-
}))
|
|
2166
|
+
document: groupByContentTypeTabs(page.contentModel, document),
|
|
2167
|
+
...page.attributes ? { attributes: page.attributes } : {}
|
|
2150
2168
|
};
|
|
2151
|
-
}
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
const page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
2180
|
-
where: {
|
|
2181
|
-
state: "published",
|
|
2182
|
-
contentId: homepageContentId,
|
|
2183
|
-
contentModel: homepageContentModel,
|
|
2184
|
-
locale: defaultLocale
|
|
2185
|
-
}
|
|
2186
|
-
});
|
|
2187
|
-
if (!page) {
|
|
2188
|
-
ctx.status = 404;
|
|
2189
|
-
return;
|
|
2190
|
-
}
|
|
2191
|
-
const properties = ctx.query.properties;
|
|
2192
|
-
if (properties && properties.includes("attributes")) {
|
|
2193
|
-
const attributes2 = await strapi2.db.query(config2.uuid.modules.attribute).findOne({
|
|
2169
|
+
},
|
|
2170
|
+
async getPages() {
|
|
2171
|
+
const ctx = strapi2.requestContext.get();
|
|
2172
|
+
const properties = ctx.query.properties;
|
|
2173
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
2174
|
+
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
2175
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
2176
|
+
where: {
|
|
2177
|
+
module: "slug",
|
|
2178
|
+
property: [
|
|
2179
|
+
"showDefaultLanguage",
|
|
2180
|
+
"homepageContentId",
|
|
2181
|
+
"homepageContentModel",
|
|
2182
|
+
"homepageSlugStrategy"
|
|
2183
|
+
]
|
|
2184
|
+
}
|
|
2185
|
+
});
|
|
2186
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
2187
|
+
const homepageContentId = settings.find(
|
|
2188
|
+
(setting) => setting.property === "homepageContentId"
|
|
2189
|
+
).value;
|
|
2190
|
+
const homepageContentModel = settings.find(
|
|
2191
|
+
(setting) => setting.property === "homepageContentModel"
|
|
2192
|
+
).value;
|
|
2193
|
+
const homepageSlugStrategy = settings.find(
|
|
2194
|
+
(setting) => setting.property === "homepageSlugStrategy"
|
|
2195
|
+
).value;
|
|
2196
|
+
const pages = await strapi2.db.query(config2.uuid.modules.slug).findMany({
|
|
2194
2197
|
where: {
|
|
2195
|
-
locale: page.locale,
|
|
2196
|
-
contentId: page.contentId,
|
|
2197
|
-
contentModel: page.contentModel,
|
|
2198
2198
|
state: "published"
|
|
2199
2199
|
}
|
|
2200
2200
|
});
|
|
2201
|
-
|
|
2201
|
+
pages.forEach((page) => {
|
|
2202
|
+
if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale === page.locale) {
|
|
2203
|
+
page.fullSlug = "";
|
|
2204
|
+
} else if (homepageContentId === page.contentId && homepageContentModel === page.contentModel && defaultLocale !== page.locale && homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
2205
|
+
page.fullSlug = page.locale.toLowerCase();
|
|
2206
|
+
} else {
|
|
2207
|
+
page.fullSlug = buildFullSlug({ pages, page, defaultLocale, showDefaultLanguage });
|
|
2208
|
+
}
|
|
2209
|
+
});
|
|
2210
|
+
if (properties && properties.includes("attributes")) {
|
|
2211
|
+
for (const page of pages) {
|
|
2212
|
+
const attributes2 = await strapi2.db.query(config2.uuid.modules.attribute).findOne({
|
|
2213
|
+
where: {
|
|
2214
|
+
locale: page.locale,
|
|
2215
|
+
contentId: page.contentId,
|
|
2216
|
+
contentModel: page.contentModel,
|
|
2217
|
+
state: "published"
|
|
2218
|
+
}
|
|
2219
|
+
});
|
|
2220
|
+
const template = attributes2 && attributes2.templateId ? await strapi2.db.query(config2.uuid.modules.template).findOne({
|
|
2221
|
+
where: {
|
|
2222
|
+
documentId: attributes2.templateId
|
|
2223
|
+
}
|
|
2224
|
+
}) : null;
|
|
2225
|
+
page.attributes = {
|
|
2226
|
+
template: template?.uid || "default",
|
|
2227
|
+
priority: attributes2?.priority || "0.5",
|
|
2228
|
+
frequency: attributes2?.frequency || "weekly",
|
|
2229
|
+
...attributes2?.parentContentId ? { parent: { id: attributes2.parentContentId, model: attributes2.parentContentModel } } : {}
|
|
2230
|
+
};
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
const mappedPages = pages.map((page) => ({
|
|
2234
|
+
...page,
|
|
2235
|
+
...page.attributes ? { attributes: page.attributes } : {},
|
|
2236
|
+
localizations: []
|
|
2237
|
+
}));
|
|
2238
|
+
const rootItems = mappedPages.filter((item) => item.locale === defaultLocale);
|
|
2239
|
+
const mappedItems = rootItems.map((rootItem) => {
|
|
2240
|
+
const relatedItems = mappedPages.filter(
|
|
2241
|
+
(item) => item.contentId === rootItem.contentId && item.contentModel === rootItem.contentModel && item.locale !== defaultLocale
|
|
2242
|
+
);
|
|
2243
|
+
return {
|
|
2244
|
+
id: rootItem.id,
|
|
2245
|
+
documentId: rootItem.contentId,
|
|
2246
|
+
slug: rootItem.fullSlug,
|
|
2247
|
+
locale: rootItem.locale,
|
|
2248
|
+
createdAt: rootItem.updatedAt,
|
|
2249
|
+
updatedAt: rootItem.updatedAt,
|
|
2250
|
+
publishedAt: rootItem.updatedAt,
|
|
2251
|
+
...rootItem.attributes ? { attributes: rootItem.attributes } : {},
|
|
2252
|
+
localizations: relatedItems.map((item) => ({
|
|
2253
|
+
id: item.id,
|
|
2254
|
+
documentId: item.contentId,
|
|
2255
|
+
slug: item.fullSlug,
|
|
2256
|
+
locale: item.locale,
|
|
2257
|
+
createdAt: item.updatedAt,
|
|
2258
|
+
updatedAt: item.updatedAt,
|
|
2259
|
+
publishedAt: item.updatedAt,
|
|
2260
|
+
...item.attributes ? { attributes: item.attributes } : {}
|
|
2261
|
+
}))
|
|
2262
|
+
};
|
|
2263
|
+
});
|
|
2264
|
+
return mappedItems;
|
|
2265
|
+
},
|
|
2266
|
+
async getHomePage() {
|
|
2267
|
+
const ctx = strapi2.requestContext.get();
|
|
2268
|
+
const config2 = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
2269
|
+
const defaultLocale = await strapi2.plugin("i18n").service("locales").getDefaultLocale();
|
|
2270
|
+
const settings = await strapi2.db.query(config2.uuid.app.setting).findMany({
|
|
2202
2271
|
where: {
|
|
2203
|
-
|
|
2272
|
+
module: "slug",
|
|
2273
|
+
property: [
|
|
2274
|
+
"showDefaultLanguage",
|
|
2275
|
+
"homepageContentId",
|
|
2276
|
+
"homepageContentModel",
|
|
2277
|
+
"homepageSlugStrategy"
|
|
2278
|
+
]
|
|
2204
2279
|
}
|
|
2205
|
-
})
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2280
|
+
});
|
|
2281
|
+
const showDefaultLanguage = settings.find((setting) => setting.property === "showDefaultLanguage").value === "true";
|
|
2282
|
+
const homepageContentId = settings.find(
|
|
2283
|
+
(setting) => setting.property === "homepageContentId"
|
|
2284
|
+
).value;
|
|
2285
|
+
const homepageContentModel = settings.find(
|
|
2286
|
+
(setting) => setting.property === "homepageContentModel"
|
|
2287
|
+
).value;
|
|
2288
|
+
const homepageSlugStrategy = settings.find(
|
|
2289
|
+
(setting) => setting.property === "homepageSlugStrategy"
|
|
2290
|
+
).value;
|
|
2291
|
+
const page = await strapi2.db.query(config2.uuid.modules.slug).findOne({
|
|
2292
|
+
where: {
|
|
2293
|
+
state: "published",
|
|
2294
|
+
contentId: homepageContentId,
|
|
2295
|
+
contentModel: homepageContentModel,
|
|
2296
|
+
locale: defaultLocale
|
|
2297
|
+
}
|
|
2298
|
+
});
|
|
2299
|
+
if (!page) {
|
|
2300
|
+
ctx.status = 404;
|
|
2301
|
+
return;
|
|
2302
|
+
}
|
|
2303
|
+
const properties = ctx.query.properties;
|
|
2304
|
+
if (properties && properties.includes("attributes")) {
|
|
2305
|
+
const attributes2 = await strapi2.db.query(config2.uuid.modules.attribute).findOne({
|
|
2306
|
+
where: {
|
|
2307
|
+
locale: page.locale,
|
|
2308
|
+
contentId: page.contentId,
|
|
2309
|
+
contentModel: page.contentModel,
|
|
2310
|
+
state: "published"
|
|
2311
|
+
}
|
|
2235
2312
|
});
|
|
2313
|
+
const template = attributes2 && attributes2.templateId ? await strapi2.db.query(config2.uuid.modules.template).findOne({
|
|
2314
|
+
where: {
|
|
2315
|
+
documentId: attributes2.templateId
|
|
2316
|
+
}
|
|
2317
|
+
}) : null;
|
|
2318
|
+
page.attributes = {
|
|
2319
|
+
template: template?.uid || "default",
|
|
2320
|
+
priority: attributes2?.priority || "0.5",
|
|
2321
|
+
frequency: attributes2?.frequency || "weekly",
|
|
2322
|
+
...attributes2?.parentContentId ? { parent: { id: attributes2.parentContentId, model: attributes2.parentContentModel } } : {}
|
|
2323
|
+
};
|
|
2236
2324
|
}
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2325
|
+
const query = properties && properties.includes("content") ? populateQueryFromContentType(strapi2, page.contentModel) : { localizations: { populate: "*" } };
|
|
2326
|
+
const document = await strapi2.documents(page.contentModel).findOne({
|
|
2327
|
+
locale: page.locale,
|
|
2328
|
+
populate: query,
|
|
2329
|
+
status: "published",
|
|
2330
|
+
documentId: page.contentId
|
|
2331
|
+
});
|
|
2332
|
+
await findDocumentIdsAndFetchSlugs({
|
|
2333
|
+
document,
|
|
2334
|
+
defaultLocale,
|
|
2335
|
+
showDefaultLanguage
|
|
2336
|
+
});
|
|
2337
|
+
for (const localization of document.localizations) {
|
|
2338
|
+
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
2339
|
+
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
2340
|
+
} else {
|
|
2341
|
+
localization.slug = await getSlugByDocumentId({
|
|
2342
|
+
contentId: localization.documentId,
|
|
2343
|
+
locale: localization.locale,
|
|
2344
|
+
defaultLocale,
|
|
2345
|
+
showDefaultLanguage,
|
|
2346
|
+
strapi: strapi2
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2246
2349
|
}
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
document
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2350
|
+
delete document.createdBy;
|
|
2351
|
+
delete document.updatedBy;
|
|
2352
|
+
document.slug = "";
|
|
2353
|
+
document.breadcrumbs = [
|
|
2354
|
+
{
|
|
2355
|
+
position: 1,
|
|
2356
|
+
name: document.title,
|
|
2357
|
+
item: ""
|
|
2358
|
+
}
|
|
2359
|
+
];
|
|
2360
|
+
return {
|
|
2361
|
+
document: groupByContentTypeTabs(page.contentModel, document),
|
|
2362
|
+
...page.attributes ? { attributes: page.attributes } : {}
|
|
2363
|
+
};
|
|
2364
|
+
}
|
|
2365
|
+
};
|
|
2366
|
+
};
|
|
2254
2367
|
async function fetchAdditionalData(params) {
|
|
2255
2368
|
const content = await params.strapi.documents(params.record.contentModel).findOne({
|
|
2256
2369
|
status: "published",
|