-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
150 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 @@ | ||
--- | ||
layout: blog | ||
authors: | ||
- "[jxom](https://twitter.com/_jxom)" | ||
- "[awkweb](https://twitter.com/awkweb)" | ||
date: November 25, 2023 | ||
--- | ||
|
||
# gm | ||
|
||
::authors | ||
|
||
we're so back. |
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,32 @@ | ||
import { style } from '@vanilla-extract/css' | ||
import { fontSizeVars, primitiveColorVars } from '../styles/vars.css.js' | ||
|
||
export const root = style({ | ||
color: primitiveColorVars.text3, | ||
fontSize: fontSizeVars[14], | ||
}) | ||
|
||
export const authors = style( | ||
{ | ||
color: primitiveColorVars.text, | ||
}, | ||
'authors', | ||
) | ||
|
||
export const link = style( | ||
{ | ||
textDecoration: 'underline', | ||
textUnderlineOffset: '2px', | ||
':hover': { | ||
color: primitiveColorVars.text2, | ||
}, | ||
}, | ||
'link', | ||
) | ||
|
||
export const separator = style( | ||
{ | ||
color: primitiveColorVars.text3, | ||
}, | ||
'separator', | ||
) |
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,47 @@ | ||
import * as styles from './Authors.css.js' | ||
|
||
export type AuthorsProps = { | ||
authors?: string | string[] | ||
date?: string | ||
} | ||
|
||
export function Authors({ authors: authors_, date }: AuthorsProps) { | ||
const authors = (() => { | ||
if (!authors_) return undefined | ||
if (Array.isArray(authors_)) return authors_ | ||
return authors_.split(',').map((author) => author.trim()) | ||
})() | ||
return ( | ||
<div className={styles.root}> | ||
{date} | ||
{authors && date ? ' by ' : 'By '} | ||
<span className={styles.authors}> | ||
{authors?.map((author, index) => { | ||
const { text, url } = parseAuthor(author) | ||
return ( | ||
<> | ||
{url ? ( | ||
<a className={styles.link} href={url} target="_blank" rel="noopener noreferrer"> | ||
{text} | ||
</a> | ||
) : ( | ||
text | ||
)} | ||
{index < authors.length - 2 && <span className={styles.separator}>, </span>} | ||
{index < authors.length - 1 && <span className={styles.separator}> & </span>} | ||
</> | ||
) | ||
})} | ||
</span> | ||
</div> | ||
) | ||
} | ||
|
||
function parseAuthor(author: string) { | ||
const match = author.match(/\[(.+)\]\((.+)\)/) | ||
if (!match) return { text: author, url: undefined } | ||
return { | ||
text: match[1], | ||
url: match[2], | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference types="mdast-util-to-hast" /> | ||
/// <reference types="mdast-util-directive" /> | ||
|
||
import type { Root } from 'mdast' | ||
import { visit } from 'unist-util-visit' | ||
import { parse } from 'yaml' | ||
|
||
export function remarkAuthors() { | ||
return (tree: Root) => { | ||
visit(tree, (node, index, parent) => { | ||
if (node.type !== 'leafDirective') return | ||
if (node.name !== 'authors') return | ||
if (!index) return | ||
|
||
const frontMatterNode = parent?.children.find((child) => child.type === 'yaml') as any | ||
if (!frontMatterNode) return | ||
|
||
const data = parse(frontMatterNode.value) | ||
;(parent?.children[index - 1] as any).children.push({ | ||
type: 'paragraph', | ||
data: { | ||
hName: 'div', | ||
hProperties: { 'data-authors': data.authors.join(','), 'data-date': data.date }, | ||
}, | ||
}) | ||
}) | ||
} | ||
} |