Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Jan 19, 2024
1 parent 968a307 commit 202e079
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion examples/lume-blog/_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Deno.test('build examples/lume-blog', async () => {
// await build(site)
// await assertSiteSnapshot(t, site)
await site.build()
.catch(err => console.error(Deno.inspect(err, { colors: true })))
.catch((err) => console.error(Deno.inspect(err, { colors: true })))

assertEquals(site.options.location, new URL('https://aoba-test.netlify.app'))
})
75 changes: 38 additions & 37 deletions lume/plugins/_experimental/object_article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,43 @@ import { Page } from 'lume/core/file.ts'

export default () => (site: Lume.Site) => {
// site.process(['.md', '.mdx'], (page, pages) => {
site.process(['.md'], (pages) => pages.forEach((page) => {
const match = page.outputPath?.match(/^\/posts\/([^\/?#]+)\/index.html$/)
if (match?.[1]) {
// Create Article Object
pages.push(Page.create({
url: `/notice/${match[1]}`,
content: JSON.stringify(
{
'@context': ['https://www.w3.org/ns/activitystreams'],
attributedTo: new URL('/actor', site.options.location).href,
// cc: [],
// TODO: test
content: page.data.children,
id: new URL(`/notice/${match[1]}`, site.options.location).href,
published: (page.data.date ?? new Date()).toISOString(),
source: {
content: page.data.content,
mediaType: 'text/markdown',
site.process(['.md'], (pages) =>
pages.forEach((page) => {
const match = page.outputPath?.match(/^\/posts\/([^\/?#]+)\/index.html$/)
if (match?.[1]) {
// Create Article Object
pages.push(Page.create({
url: `/notice/${match[1]}`,
content: JSON.stringify(
{
'@context': ['https://www.w3.org/ns/activitystreams'],
attributedTo: new URL('/actor', site.options.location).href,
// cc: [],
// TODO: test
content: page.data.children,
id: new URL(`/notice/${match[1]}`, site.options.location).href,
published: (page.data.date ?? new Date()).toISOString(),
source: {
content: page.data.content,
mediaType: 'text/markdown',
},
tag: [],
to: 'https://www.w3.org/ns/activitystreams#Public',
type: 'Article',
},
tag: [],
to: 'https://www.w3.org/ns/activitystreams#Public',
type: 'Article',
},
null,
2,
),
}))
// Set <link rel="alternate" type="application/activity+json" />
const link = page.document!.createElement('link')
link?.setAttribute('rel', 'alternate')
link?.setAttribute('type', 'application/activity+json')
link?.setAttribute(
'href',
new URL(`/notice/${match[1]}`, site.options.location).href,
)
page.document!.head.appendChild(link)
}
}))
null,
2,
),
}))
// Set <link rel="alternate" type="application/activity+json" />
const link = page.document!.createElement('link')
link?.setAttribute('rel', 'alternate')
link?.setAttribute('type', 'application/activity+json')
link?.setAttribute(
'href',
new URL(`/notice/${match[1]}`, site.options.location).href,
)
page.document!.head.appendChild(link)
}
}))
}
41 changes: 22 additions & 19 deletions lume/plugins/hatsu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,28 @@ export const hatsuPlugin = (options: Options): Plugin => (site: Lume.Site) => {
})

// set <link rel="alternate" type="application/activity+json" /> for matched page
site.process(['.html'], (pages) => pages.forEach((page) => {
// console.log(page.outputPath, page.data.url)
if (
page.document &&
(!options.match || options.match?.some((matcher) => (page.data.url as string).match(matcher)))
) {
const link = page.document.createElement('link')
link?.setAttribute('rel', 'alternate')
link?.setAttribute('type', 'application/activity+json')
link?.setAttribute(
'href',
new URL(
`/o/${new URL(page.data.url, site.options.location).href}`,
options.instance,
).href,
)
page.document.head.appendChild(link)
}
}))
site.process(['.html'], (pages) =>
pages.forEach((page) => {
// console.log(page.outputPath, page.data.url)
if (
page.document &&
(!options.match || options.match?.some((matcher) =>
(page.data.url as string).match(matcher)
))
) {
const link = page.document.createElement('link')
link?.setAttribute('rel', 'alternate')
link?.setAttribute('type', 'application/activity+json')
link?.setAttribute(
'href',
new URL(
`/o/${new URL(page.data.url, site.options.location).href}`,
options.instance,
).href,
)
page.document.head.appendChild(link)
}
}))
}

export default hatsuPlugin

0 comments on commit 202e079

Please sign in to comment.