Skip to content

Commit

Permalink
fix: reset layout options between page
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Nov 15, 2024
1 parent 17a2ea2 commit 57fb65d
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions src/client/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ function createPageData() {
typeof window.$$SolidBase_page_data[component.src.split("?")[0]] !==
"undefined"
) {
// @ts-ignore
return window.$$SolidBase_page_data[
component.src.split("?")[0]
] as CurrentPageData;
return computeLayout(
// @ts-ignore
window.$$SolidBase_page_data[
component.src.split("?")[0]
] as CurrentPageData,
);
}

const manifest = import.meta.env.SSR
Expand All @@ -134,31 +136,35 @@ function createPageData() {
const pd = (mod?.$$SolidBase_page_data ??
defaultPageData) as CurrentPageData;

pd.layout = defaultPageData.layout;

pd.layout!.prev = pd.frontmatter.prev;
pd.layout!.next = pd.frontmatter.next;

switch (pd.frontmatter.layout) {
case "home":
pd.layout!.editLink = false;
pd.layout!.lastUpdated = false;
pd.layout!.next = false;
pd.layout!.prev = false;
pd.layout!.sidebar = false;
pd.layout!.toc = false;
pd.layout!.footer = true;
}

for (const k in Object.keys(pd.layout ?? {})) {
// @ts-ignore
if (pd.frontmatter[k]) pd.layout[k] = pd.frontmatter[k];
}

return pd;
return computeLayout(pd);
},
{ initialValue: defaultPageData },
);

return pageData;
}

function computeLayout(pd: CurrentPageData): CurrentPageData {
pd.layout = structuredClone(defaultPageData.layout);

pd.layout!.prev = pd.frontmatter.prev;
pd.layout!.next = pd.frontmatter.next;

switch (pd.frontmatter.layout) {
case "home":
pd.layout!.editLink = false;
pd.layout!.lastUpdated = false;
pd.layout!.next = false;
pd.layout!.prev = false;
pd.layout!.sidebar = false;
pd.layout!.toc = false;
pd.layout!.footer = true;
}

for (const k in Object.keys(pd.layout ?? {})) {
// @ts-ignore
if (pd.frontmatter[k]) pd.layout[k] = pd.frontmatter[k];
}

return pd;
}

0 comments on commit 57fb65d

Please sign in to comment.