@littlebox/strapi-suite 1.0.41 → 1.0.43
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
CHANGED
|
@@ -203,6 +203,7 @@ GET /api/littlebox-strapi-suite/modules/pages?slug=<SLUG>
|
|
|
203
203
|
Using the slug module settings (as shown in the screenshot above), you can choose which content will be set as the homepage. Then, just call the API to get the data:
|
|
204
204
|
```
|
|
205
205
|
GET /api/littlebox-strapi-suite/modules/pages/home?properties=attributes
|
|
206
|
+
GET /api/littlebox-strapi-suite/modules/pages/home?properties=attributes,content
|
|
206
207
|
```
|
|
207
208
|
The return will be the content in the default language and the respective localizations:
|
|
208
209
|
```
|
package/dist/server/index.js
CHANGED
|
@@ -1598,6 +1598,7 @@ async function getSlugByDocumentId(params) {
|
|
|
1598
1598
|
state: "published"
|
|
1599
1599
|
}
|
|
1600
1600
|
});
|
|
1601
|
+
if (!document) return null;
|
|
1601
1602
|
if (document.parentContentId) {
|
|
1602
1603
|
const parentSlug = await getSlugByDocumentId({
|
|
1603
1604
|
contentId: document.parentContentId,
|
|
@@ -1744,14 +1745,16 @@ function handleAttributes(attributes2) {
|
|
|
1744
1745
|
break;
|
|
1745
1746
|
case "relation":
|
|
1746
1747
|
if (key === "roles" || key === "users" || key === "createdBy" || key === "updatedBy") break;
|
|
1747
|
-
query[key] =
|
|
1748
|
+
query[key] = { populate: "*" };
|
|
1748
1749
|
break;
|
|
1749
1750
|
case "dynamiczone":
|
|
1750
1751
|
const components = attributes2[key]["components"];
|
|
1751
1752
|
query[key] = { on: {} };
|
|
1752
1753
|
components.forEach((component) => {
|
|
1753
1754
|
const componentData2 = strapi.components[component];
|
|
1754
|
-
query[key]["on"][component] = {
|
|
1755
|
+
query[key]["on"][component] = {
|
|
1756
|
+
populate: handleAttributes(componentData2.attributes)
|
|
1757
|
+
};
|
|
1755
1758
|
});
|
|
1756
1759
|
break;
|
|
1757
1760
|
}
|
|
@@ -1763,6 +1766,41 @@ function populateQueryFromContentType(strapi2, contentType) {
|
|
|
1763
1766
|
const query = handleAttributes(attributes2);
|
|
1764
1767
|
return query;
|
|
1765
1768
|
}
|
|
1769
|
+
async function findDocumentIdsAndFetchSlugs(params) {
|
|
1770
|
+
if (!params.document || typeof params.document !== "object") return;
|
|
1771
|
+
const promises = [];
|
|
1772
|
+
async function traverse(current) {
|
|
1773
|
+
if (!current || typeof current !== "object") return;
|
|
1774
|
+
if (Array.isArray(current)) {
|
|
1775
|
+
for (let i = 0; i < current.length; i++) {
|
|
1776
|
+
await traverse(current[i]);
|
|
1777
|
+
}
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1780
|
+
if ("documentId" in current) {
|
|
1781
|
+
promises.push(
|
|
1782
|
+
(async () => {
|
|
1783
|
+
const slug = await getSlugByDocumentId({
|
|
1784
|
+
contentId: current.documentId,
|
|
1785
|
+
locale: current.locale,
|
|
1786
|
+
defaultLocale: params.defaultLocale,
|
|
1787
|
+
showDefaultLanguage: params.showDefaultLanguage,
|
|
1788
|
+
strapi
|
|
1789
|
+
});
|
|
1790
|
+
current.slug = slug;
|
|
1791
|
+
})()
|
|
1792
|
+
);
|
|
1793
|
+
}
|
|
1794
|
+
for (const key in current) {
|
|
1795
|
+
if (Object.prototype.hasOwnProperty.call(current, key) && current[key] !== null) {
|
|
1796
|
+
await traverse(current[key]);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
await traverse(params.document);
|
|
1801
|
+
await Promise.all(promises);
|
|
1802
|
+
return params.document;
|
|
1803
|
+
}
|
|
1766
1804
|
const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
1767
1805
|
async adminGetAll() {
|
|
1768
1806
|
const ctx = strapi2.requestContext.get();
|
|
@@ -1890,6 +1928,11 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1890
1928
|
status: "published",
|
|
1891
1929
|
documentId: page.contentId
|
|
1892
1930
|
});
|
|
1931
|
+
await findDocumentIdsAndFetchSlugs({
|
|
1932
|
+
document,
|
|
1933
|
+
defaultLocale,
|
|
1934
|
+
showDefaultLanguage
|
|
1935
|
+
});
|
|
1893
1936
|
for (const localization of document.localizations) {
|
|
1894
1937
|
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && localization.documentId === homepageContentId) {
|
|
1895
1938
|
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
@@ -2075,13 +2118,18 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
2075
2118
|
...attributes2?.parentContentId ? { parent: { id: attributes2.parentContentId, model: attributes2.parentContentModel } } : {}
|
|
2076
2119
|
};
|
|
2077
2120
|
}
|
|
2078
|
-
const query = populateQueryFromContentType(strapi2, page.contentModel);
|
|
2121
|
+
const query = properties && properties.includes("content") ? populateQueryFromContentType(strapi2, page.contentModel) : { localizations: { populate: "*" } };
|
|
2079
2122
|
const document = await strapi2.documents(page.contentModel).findOne({
|
|
2080
2123
|
locale: page.locale,
|
|
2081
2124
|
populate: query,
|
|
2082
2125
|
status: "published",
|
|
2083
2126
|
documentId: page.contentId
|
|
2084
2127
|
});
|
|
2128
|
+
await findDocumentIdsAndFetchSlugs({
|
|
2129
|
+
document,
|
|
2130
|
+
defaultLocale,
|
|
2131
|
+
showDefaultLanguage
|
|
2132
|
+
});
|
|
2085
2133
|
for (const localization of document.localizations) {
|
|
2086
2134
|
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
2087
2135
|
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
package/dist/server/index.mjs
CHANGED
|
@@ -1597,6 +1597,7 @@ async function getSlugByDocumentId(params) {
|
|
|
1597
1597
|
state: "published"
|
|
1598
1598
|
}
|
|
1599
1599
|
});
|
|
1600
|
+
if (!document) return null;
|
|
1600
1601
|
if (document.parentContentId) {
|
|
1601
1602
|
const parentSlug = await getSlugByDocumentId({
|
|
1602
1603
|
contentId: document.parentContentId,
|
|
@@ -1743,14 +1744,16 @@ function handleAttributes(attributes2) {
|
|
|
1743
1744
|
break;
|
|
1744
1745
|
case "relation":
|
|
1745
1746
|
if (key === "roles" || key === "users" || key === "createdBy" || key === "updatedBy") break;
|
|
1746
|
-
query[key] =
|
|
1747
|
+
query[key] = { populate: "*" };
|
|
1747
1748
|
break;
|
|
1748
1749
|
case "dynamiczone":
|
|
1749
1750
|
const components = attributes2[key]["components"];
|
|
1750
1751
|
query[key] = { on: {} };
|
|
1751
1752
|
components.forEach((component) => {
|
|
1752
1753
|
const componentData2 = strapi.components[component];
|
|
1753
|
-
query[key]["on"][component] = {
|
|
1754
|
+
query[key]["on"][component] = {
|
|
1755
|
+
populate: handleAttributes(componentData2.attributes)
|
|
1756
|
+
};
|
|
1754
1757
|
});
|
|
1755
1758
|
break;
|
|
1756
1759
|
}
|
|
@@ -1762,6 +1765,41 @@ function populateQueryFromContentType(strapi2, contentType) {
|
|
|
1762
1765
|
const query = handleAttributes(attributes2);
|
|
1763
1766
|
return query;
|
|
1764
1767
|
}
|
|
1768
|
+
async function findDocumentIdsAndFetchSlugs(params) {
|
|
1769
|
+
if (!params.document || typeof params.document !== "object") return;
|
|
1770
|
+
const promises = [];
|
|
1771
|
+
async function traverse(current) {
|
|
1772
|
+
if (!current || typeof current !== "object") return;
|
|
1773
|
+
if (Array.isArray(current)) {
|
|
1774
|
+
for (let i = 0; i < current.length; i++) {
|
|
1775
|
+
await traverse(current[i]);
|
|
1776
|
+
}
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
if ("documentId" in current) {
|
|
1780
|
+
promises.push(
|
|
1781
|
+
(async () => {
|
|
1782
|
+
const slug = await getSlugByDocumentId({
|
|
1783
|
+
contentId: current.documentId,
|
|
1784
|
+
locale: current.locale,
|
|
1785
|
+
defaultLocale: params.defaultLocale,
|
|
1786
|
+
showDefaultLanguage: params.showDefaultLanguage,
|
|
1787
|
+
strapi
|
|
1788
|
+
});
|
|
1789
|
+
current.slug = slug;
|
|
1790
|
+
})()
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1793
|
+
for (const key in current) {
|
|
1794
|
+
if (Object.prototype.hasOwnProperty.call(current, key) && current[key] !== null) {
|
|
1795
|
+
await traverse(current[key]);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
await traverse(params.document);
|
|
1800
|
+
await Promise.all(promises);
|
|
1801
|
+
return params.document;
|
|
1802
|
+
}
|
|
1765
1803
|
const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
1766
1804
|
async adminGetAll() {
|
|
1767
1805
|
const ctx = strapi2.requestContext.get();
|
|
@@ -1889,6 +1927,11 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
1889
1927
|
status: "published",
|
|
1890
1928
|
documentId: page.contentId
|
|
1891
1929
|
});
|
|
1930
|
+
await findDocumentIdsAndFetchSlugs({
|
|
1931
|
+
document,
|
|
1932
|
+
defaultLocale,
|
|
1933
|
+
showDefaultLanguage
|
|
1934
|
+
});
|
|
1892
1935
|
for (const localization of document.localizations) {
|
|
1893
1936
|
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY && localization.documentId === homepageContentId) {
|
|
1894
1937
|
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
|
@@ -2074,13 +2117,18 @@ const SlugModuleService = ({ strapi: strapi2 }) => ({
|
|
|
2074
2117
|
...attributes2?.parentContentId ? { parent: { id: attributes2.parentContentId, model: attributes2.parentContentModel } } : {}
|
|
2075
2118
|
};
|
|
2076
2119
|
}
|
|
2077
|
-
const query = populateQueryFromContentType(strapi2, page.contentModel);
|
|
2120
|
+
const query = properties && properties.includes("content") ? populateQueryFromContentType(strapi2, page.contentModel) : { localizations: { populate: "*" } };
|
|
2078
2121
|
const document = await strapi2.documents(page.contentModel).findOne({
|
|
2079
2122
|
locale: page.locale,
|
|
2080
2123
|
populate: query,
|
|
2081
2124
|
status: "published",
|
|
2082
2125
|
documentId: page.contentId
|
|
2083
2126
|
});
|
|
2127
|
+
await findDocumentIdsAndFetchSlugs({
|
|
2128
|
+
document,
|
|
2129
|
+
defaultLocale,
|
|
2130
|
+
showDefaultLanguage
|
|
2131
|
+
});
|
|
2084
2132
|
for (const localization of document.localizations) {
|
|
2085
2133
|
if (homepageSlugStrategy === SLUG_LANGUAGE_STRATEGY) {
|
|
2086
2134
|
localization.slug = localization.locale === defaultLocale ? "" : localization.locale.toLowerCase();
|
package/package.json
CHANGED