-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
childPages
to context of index pages
This property now gets (on-demand) the immediate children of an index page. - Types (including arguments for generic types) created for the new property - Pages getter can now take an array of globs instead of just a glob string - New `contentPath` property on `Location` to make it easier to work with content directory-relative paths
- Loading branch information
Showing
14 changed files
with
203 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,13 @@ or email [email protected] <mailto:[email protected]> | |
*/ | ||
|
||
import type { | ||
Page, | ||
Context, | ||
Element, | ||
ElementCreator, | ||
ElementRenderer, | ||
ElementRendererCreator, | ||
Location, | ||
Page, | ||
Props, | ||
} from "../domain.ts"; | ||
import { path } from "../deps.ts"; | ||
|
@@ -48,6 +49,14 @@ const renderProps = (props?: Props): string => { | |
); | ||
}; | ||
|
||
const _shouldHaveChildPages = ({ contentPath }: Location) => | ||
contentPath.split(path.sep).pop() === "index.md"; | ||
|
||
const _getChildPagesGlobs = ({ contentPath }: Location): string[] => { | ||
const contentDir = path.dirname(contentPath); | ||
return [`${contentDir}/!(index).md`, `${contentDir}/*/index.md`]; | ||
}; | ||
|
||
export const createRenderer: ElementRendererCreator = (options, getPages) => | ||
(contentPage) => { | ||
const renderContext = { | ||
|
@@ -83,6 +92,12 @@ export const createRenderer: ElementRendererCreator = (options, getPages) => | |
const context: Context = { | ||
page: contentPage as Page, | ||
needsCss: renderContext.needsCss, | ||
get childPages() { | ||
if (getPages && _shouldHaveChildPages(this.page.location)) { | ||
return getPages(_getChildPagesGlobs(this.page.location)); | ||
} | ||
return undefined; | ||
}, | ||
}; | ||
if (component.wantsPages) { | ||
context.wantedPages = getPages && | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
--- | ||
title: Index page | ||
--- | ||
|
||
# Welcome to my page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: List page | ||
--- | ||
|
||
# Welcome to my page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<body><h1 id="welcome-to-my-page">Welcome to my page</h1> | ||
<main><article><h2>This is the first page</h2>I have some content here. Since this text is not very long, all of it will be used as a summary. Normally, the summary is capped at 500 characters.</article><article><h2>This is the second page</h2>The second page is not very interesting, move on please.</article><article><h2>This is the third page</h2>I know you're out there. I can feel you now. I know that you're afraid... you're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world without you.</article></main></body> | ||
<main><article><h2>List page</h2>Welcome to my page</article><article><h2>This is the first page</h2>I have some content here. Since this text is not very long, all of it will be used as a summary. Normally, the summary is capped at 500 characters.</article><article><h2>This is the second page</h2>The second page is not very interesting, move on please.</article><article><h2>This is the third page</h2>I know you're out there. I can feel you now. I know that you're afraid... you're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world without you.</article></main></body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<body><h1 id="welcome-to-my-page">Welcome to my page</h1> | ||
<main><article><h2>This is the first page</h2>I have some content here. Since this text is not very long, all of it will be used as a summary. Normally, the summary is capped at 500 characters.</article><article><h2>This is the second page</h2>The second page is not very interesting, move on please.</article><article><h2>This is the third page</h2>I know you're out there. I can feel you now. I know that you're afraid... you're afraid of us. You're afraid of change. I don't know the future. I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin. I'm going to hang up this phone, and then I'm going to show these people what you don't want them to see. I'm going to show them a world without you.</article></main></body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** @jsx h */ | ||
|
||
import { Component, h } from "../../../../../mod.ts"; | ||
|
||
type EmptyObject = Record<string, never>; | ||
|
||
const Index: Component<EmptyObject, unknown, EmptyObject> = ( | ||
_props, | ||
{ page: { content }, wantedPages }, | ||
) => ( | ||
<body> | ||
{content} | ||
<main> | ||
{wantedPages?.map((page) => ( | ||
<article> | ||
<h2>{page.title}</h2> | ||
{page.summary} | ||
</article> | ||
))} | ||
</main> | ||
</body> | ||
); | ||
|
||
Index.wantsPages = "!(index).md"; | ||
|
||
export default Index; |
Oops, something went wrong.