@farming-labs/next 0.1.69 → 0.1.71
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/dist/config.mjs +111 -0
- package/package.json +3 -3
package/dist/config.mjs
CHANGED
|
@@ -860,6 +860,106 @@ function dedupeRewrites(rewrites) {
|
|
|
860
860
|
}
|
|
861
861
|
return result;
|
|
862
862
|
}
|
|
863
|
+
function dedupeRedirects(redirects) {
|
|
864
|
+
const seen = /* @__PURE__ */ new Set();
|
|
865
|
+
const result = [];
|
|
866
|
+
for (const redirect of redirects) {
|
|
867
|
+
const key = redirect.source;
|
|
868
|
+
if (seen.has(key)) continue;
|
|
869
|
+
seen.add(key);
|
|
870
|
+
result.push(redirect);
|
|
871
|
+
}
|
|
872
|
+
return result;
|
|
873
|
+
}
|
|
874
|
+
function resolveDocsPageSourceFile(dir) {
|
|
875
|
+
return ["page.mdx", "page.md"].map((fileName) => join(dir, fileName)).find((candidate) => existsSync(candidate));
|
|
876
|
+
}
|
|
877
|
+
function readDocsPageFrontmatter(filePath) {
|
|
878
|
+
try {
|
|
879
|
+
return matter(readFileSync(filePath, "utf-8")).data;
|
|
880
|
+
} catch {
|
|
881
|
+
return {};
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
function resolveDocsPageOrder(dir) {
|
|
885
|
+
const pageSource = resolveDocsPageSourceFile(dir);
|
|
886
|
+
if (!pageSource) return Number.POSITIVE_INFINITY;
|
|
887
|
+
const data = readDocsPageFrontmatter(pageSource);
|
|
888
|
+
return typeof data.order === "number" ? data.order : Number.POSITIVE_INFINITY;
|
|
889
|
+
}
|
|
890
|
+
function resolveDocsPageFolderIndexBehavior(data) {
|
|
891
|
+
const sidebar = data.sidebar;
|
|
892
|
+
if (!sidebar || typeof sidebar !== "object") return void 0;
|
|
893
|
+
const value = sidebar.folderIndexBehavior;
|
|
894
|
+
return value === "link" || value === "toggle" || value === "hidden" ? value : void 0;
|
|
895
|
+
}
|
|
896
|
+
function listSortedDocsChildDirectories(dir) {
|
|
897
|
+
let entries;
|
|
898
|
+
try {
|
|
899
|
+
entries = readdirSync(dir);
|
|
900
|
+
} catch {
|
|
901
|
+
return [];
|
|
902
|
+
}
|
|
903
|
+
return entries.map((name) => ({
|
|
904
|
+
name,
|
|
905
|
+
fullPath: join(dir, name)
|
|
906
|
+
})).filter(({ fullPath }) => {
|
|
907
|
+
try {
|
|
908
|
+
return statSync(fullPath).isDirectory();
|
|
909
|
+
} catch {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
}).sort((left, right) => {
|
|
913
|
+
const leftOrder = resolveDocsPageOrder(left.fullPath);
|
|
914
|
+
const rightOrder = resolveDocsPageOrder(right.fullPath);
|
|
915
|
+
if (leftOrder !== rightOrder) return leftOrder - rightOrder;
|
|
916
|
+
return left.name.localeCompare(right.name);
|
|
917
|
+
}).map(({ name }) => name);
|
|
918
|
+
}
|
|
919
|
+
function findFirstVisibleDocsChildSlug(dir, slugParts) {
|
|
920
|
+
for (const name of listSortedDocsChildDirectories(dir)) {
|
|
921
|
+
const childDir = join(dir, name);
|
|
922
|
+
const childSlugParts = [...slugParts, name];
|
|
923
|
+
const pageSource = resolveDocsPageSourceFile(childDir);
|
|
924
|
+
if (!pageSource) {
|
|
925
|
+
const descendant = findFirstVisibleDocsChildSlug(childDir, childSlugParts);
|
|
926
|
+
if (descendant) return descendant;
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
const data = readDocsPageFrontmatter(pageSource);
|
|
930
|
+
const folderIndexBehavior = resolveDocsPageFolderIndexBehavior(data);
|
|
931
|
+
if (data.hidden === true || folderIndexBehavior === "hidden") {
|
|
932
|
+
const descendant = findFirstVisibleDocsChildSlug(childDir, childSlugParts);
|
|
933
|
+
if (descendant) return descendant;
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
return childSlugParts;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
function buildHiddenFolderRedirects(docsDir, entry) {
|
|
940
|
+
const redirects = [];
|
|
941
|
+
function scan(dir, slugParts) {
|
|
942
|
+
if (!existsSync(dir)) return;
|
|
943
|
+
const pageSource = resolveDocsPageSourceFile(dir);
|
|
944
|
+
if (pageSource) {
|
|
945
|
+
if (resolveDocsPageFolderIndexBehavior(readDocsPageFrontmatter(pageSource)) === "hidden") {
|
|
946
|
+
const destinationSlug = findFirstVisibleDocsChildSlug(dir, slugParts);
|
|
947
|
+
if (destinationSlug && destinationSlug.join("/") !== slugParts.join("/")) {
|
|
948
|
+
const source = slugParts.length > 0 ? `/${entry}/${slugParts.join("/")}` : `/${entry}`;
|
|
949
|
+
const destination = destinationSlug.length > 0 ? `/${entry}/${destinationSlug.join("/")}` : `/${entry}`;
|
|
950
|
+
redirects.push({
|
|
951
|
+
source,
|
|
952
|
+
destination,
|
|
953
|
+
permanent: false
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
for (const name of listSortedDocsChildDirectories(dir)) scan(join(dir, name), [...slugParts, name]);
|
|
959
|
+
}
|
|
960
|
+
scan(docsDir, []);
|
|
961
|
+
return dedupeRedirects(redirects);
|
|
962
|
+
}
|
|
863
963
|
function mergeDocsMarkdownRewrites(entry, mcp, agentFeedback, result) {
|
|
864
964
|
const autoRewrites = [
|
|
865
965
|
...buildAgentSpecRewrites(),
|
|
@@ -880,6 +980,9 @@ function mergeDocsMarkdownRewrites(entry, mcp, agentFeedback, result) {
|
|
|
880
980
|
fallback: result.fallback ?? []
|
|
881
981
|
};
|
|
882
982
|
}
|
|
983
|
+
function mergeDocsRedirects(autoRedirects, redirects) {
|
|
984
|
+
return dedupeRedirects([...redirects ?? [], ...autoRedirects]);
|
|
985
|
+
}
|
|
883
986
|
function withDocs(nextConfig = {}) {
|
|
884
987
|
const root = process.cwd();
|
|
885
988
|
const workspaceRoot = findDocsWorkspaceRoot(root);
|
|
@@ -1053,11 +1156,19 @@ function withDocs(nextConfig = {}) {
|
|
|
1053
1156
|
const existingTracingIncludes = nextConfig.outputFileTracingIncludes ?? {};
|
|
1054
1157
|
const docsTraceGlob = docsContentDir.replace(/\\/g, "/").replace(/^\.?\//, "") + "/**/*";
|
|
1055
1158
|
const skillTraceFile = "skill.md";
|
|
1159
|
+
const docsContentRoot = isAbsolute(docsContentDir) ? docsContentDir : join(root, docsContentDir);
|
|
1056
1160
|
if (!isStaticExport) {
|
|
1057
1161
|
const existingRewrites = nextConfig.rewrites;
|
|
1058
1162
|
nextConfig.rewrites = async () => {
|
|
1059
1163
|
return mergeDocsMarkdownRewrites(entry, mcp, agentFeedback, typeof existingRewrites === "function" ? await existingRewrites() : existingRewrites);
|
|
1060
1164
|
};
|
|
1165
|
+
const autoRedirects = buildHiddenFolderRedirects(docsContentRoot, entry);
|
|
1166
|
+
if (autoRedirects.length > 0) {
|
|
1167
|
+
const existingRedirects = nextConfig.redirects;
|
|
1168
|
+
nextConfig.redirects = async () => {
|
|
1169
|
+
return mergeDocsRedirects(autoRedirects, typeof existingRedirects === "function" ? await existingRedirects() : existingRedirects);
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1061
1172
|
}
|
|
1062
1173
|
nextConfig.outputFileTracingIncludes = {
|
|
1063
1174
|
...existingTracingIncludes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/next",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.71",
|
|
4
4
|
"description": "Next.js adapter for @farming-labs/docs — MDX config wrapper",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -95,8 +95,8 @@
|
|
|
95
95
|
"tsdown": "^0.20.3",
|
|
96
96
|
"typescript": "^5.9.3",
|
|
97
97
|
"vitest": "^3.2.4",
|
|
98
|
-
"@farming-labs/theme": "0.1.
|
|
99
|
-
"@farming-labs/docs": "0.1.
|
|
98
|
+
"@farming-labs/theme": "0.1.71",
|
|
99
|
+
"@farming-labs/docs": "0.1.71"
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
102
|
"@farming-labs/docs": ">=0.0.1",
|