-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support collection options in nextjs publishing (#1277)
* chore: add util to grab custom header content * chore: add DendronCustomHead component * feat: add custom head content to head of every note * chore: fix typo * feat: support collection options in nextjs publishing * chore: make collection items into a component * chore: clean up utils * chore: remove just-the-doc specific css classes * chore: fix tag closing * chore: minor fixes Co-authored-by: Kevin Lin <kevinslin8@gmail.com> Co-authored-by: Kevin <kevin@dendron.so>
- Loading branch information
1 parent
8e6dce5
commit ddaedd4
Showing
7 changed files
with
123 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { NoteProps } from "@dendronhq/common-all"; | ||
import { getNoteUrl } from "../utils/links"; | ||
import _ from "lodash"; | ||
import Link from "next/link"; | ||
import { DateTime } from "luxon"; | ||
|
||
export function DendronCollectionItem(props: { | ||
note: NoteProps; | ||
noteIndex: NoteProps; | ||
}) { | ||
const { note, noteIndex } = props; | ||
const href = getNoteUrl({ note, noteIndex }); | ||
let publishedDate: string | undefined; | ||
try { | ||
publishedDate = _.get(note, "custom.date", false) | ||
? ISO2FormattedDate(note.custom.date, DateTime.DATE_SHORT) | ||
: millisToFormattedDate(note.created, DateTime.DATE_SHORT); | ||
} catch (err) { | ||
throw Error(`no date found for note ${note.id}`); | ||
} | ||
|
||
return ( | ||
<div> | ||
<article itemScope itemType="https://schema.org/CreativeWork"> | ||
<h2 itemProp="headline"> | ||
<Link href={href}>{note.title}</Link> | ||
</h2> | ||
{!_.isUndefined(publishedDate) && <p>{publishedDate}</p>} | ||
{_.has(note, "custom.excerpt") && ( | ||
<p itemProp="description">{note.custom.excerpt}</p> | ||
)} | ||
</article> | ||
</div> | ||
); | ||
} | ||
|
||
export function prepChildrenForCollection( | ||
note: NoteProps, | ||
notes: any, | ||
noteIndex: NoteProps | ||
) { | ||
if (note.children.length <= 0) { | ||
return; | ||
} | ||
// console.log({note, notes, noteIndex}); | ||
let children = note.children.map((id) => notes[id]); | ||
children = _.sortBy(children, (ent) => { | ||
if (_.has(ent, "custom.date")) { | ||
const dt = DateTime.fromISO(ent.custom.date); | ||
return dt.toMillis(); | ||
} | ||
return ent.created; | ||
}); | ||
if (_.get(note, "custom.sort_order", "normal") === "reverse") { | ||
children = _.reverse(children); | ||
} | ||
return children; | ||
} | ||
|
||
function ISO2FormattedDate(time: string, format: Intl.DateTimeFormatOptions) { | ||
const dt = DateTime.fromISO(time); | ||
return dt.toLocaleString(format); | ||
} | ||
|
||
function millisToJSDate(ts: number) { | ||
const dt = DateTime.fromMillis(_.toInteger(ts)); | ||
return dt.toJSDate(); | ||
} | ||
|
||
function millisToFormattedDate(ts: number, format: Intl.DateTimeFormatOptions) { | ||
const dt = DateTime.fromMillis(ts); | ||
return dt.toLocaleString(format); | ||
} |
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
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