-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add comments and css code highlight (minor changes)
- Loading branch information
Showing
17 changed files
with
314 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
import { Code } from 'astro:components'; | ||
interface Props { | ||
url: string; | ||
lang: string; | ||
} | ||
const codeUrl = async (url: string) => { | ||
const code = await fetch(url).then((res) => res.text()); | ||
return code; | ||
}; | ||
const { url, lang } = Astro.props; | ||
const code = await codeUrl(url); | ||
--- | ||
|
||
<Code code={code} lang={lang} theme="css-variables" /> | ||
|
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,93 @@ | ||
import { createEffect, createResource } from "solid-js"; | ||
import styles from './style.module.css'; | ||
|
||
const instance = 'https://fosstodon.org'; | ||
const fetchComments = async (id: string) => { | ||
const url = instance + '/api/v1/statuses/' + id + '/context'; | ||
|
||
const response = await fetch(url); | ||
return (await response.json()) as { | ||
ancestors: Comment[]; | ||
descendants: Comment[]; | ||
}; | ||
} | ||
|
||
interface Comment { | ||
account: { | ||
display_name: string; | ||
avatar_static: string; | ||
url: string; | ||
}; | ||
content: string; | ||
created_at: string; | ||
uri: string; | ||
url: string; | ||
replies_count: number; | ||
reblogs_count: number; | ||
favourites_count: number; | ||
} | ||
|
||
const Comment = (props: { comment: Comment }) => { | ||
return ( | ||
<article class={styles.comment + ' theme-card'}> | ||
<header> | ||
<div> | ||
<img src={props.comment.account.avatar_static} alt="" width="32" height="32" /> | ||
<h3> | ||
<a href={props.comment.account.url}> | ||
{props.comment.account.display_name} | ||
</a> | ||
</h3> | ||
</div> | ||
{props.comment.created_at && | ||
<p> | ||
<a href={props.comment.url}> | ||
{(new Date(props.comment.created_at)).toDateString()} | ||
</a> | ||
</p> | ||
} | ||
</header> | ||
<div> | ||
<div class={styles.ccontent} innerHTML={props.comment.content} /> | ||
<div class={styles.meta}> | ||
<a href={props.comment.url}> | ||
{props.comment.replies_count} Replies, {' '} | ||
{props.comment.reblogs_count} Reblogs, {' '} | ||
{props.comment.favourites_count} Favourites | ||
</a> | ||
</div> | ||
</div> | ||
</article> | ||
); | ||
} | ||
|
||
export const Commint = (props: { tootId: string }) => { | ||
// console.log('COMMINT'); | ||
|
||
const [data, { refetch, }] = createResource(async () => fetchComments(props.tootId)); | ||
|
||
createEffect(() => { | ||
const d = data(); | ||
console.log({ d }); | ||
}); | ||
return ( | ||
<div> | ||
{data.loading && <p>Loading...</p>} | ||
{data.error && <p>Error: {data.error}</p>} | ||
{data() && ( | ||
<> | ||
<h2>Comments:</h2> | ||
<p> | ||
<a href={instance + '/web/statuses/' + props.tootId}>View on Mastodon</a> | ||
</p> | ||
<br /> | ||
<div class={styles.comments}> | ||
{data()!.descendants.map((comment: Comment) => ( | ||
<Comment comment={comment} /> | ||
))} | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} |
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,55 @@ | ||
.comments { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
} | ||
|
||
.comment { | ||
padding: 1em; | ||
border-radius: calc(2 * var(--border-radius)); | ||
|
||
header { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
> div { | ||
display: flex; | ||
align-items: center; | ||
gap: 0.5em; | ||
} | ||
h3, | ||
p { | ||
margin: 0; | ||
} | ||
img { | ||
width: 2rem; | ||
height: 2rem; | ||
border-radius: 50%; | ||
flex-grow: 0; | ||
flex-shrink: 0; | ||
margin: 0; | ||
} | ||
} | ||
|
||
.ccontent { | ||
padding: 0.5em; | ||
p { | ||
margin: 0.5em 0; | ||
} | ||
} | ||
|
||
.meta { | ||
display: flex; | ||
justify-content: flex-end; | ||
align-items: center; | ||
gap: 0.5em; | ||
font-size: 0.8em; | ||
color: #666; | ||
|
||
a { | ||
text-decoration: none; | ||
border-bottom: none; | ||
} | ||
} | ||
} |
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,42 @@ | ||
--- | ||
title: 'Comments via Mastodon' | ||
date: 2024-10-13 | ||
description: "Replaced comments with Mastodon's context API calls." | ||
|
||
categories: ["tech"] | ||
tags: ["tech", "software"] | ||
|
||
tootId: "113034812167024055" | ||
hideTOC: true | ||
--- | ||
|
||
import CodeEmbed from '../../components/codeembed.astro'; | ||
|
||
I have replaced the comment mechanism of this website again. | ||
|
||
I looked into [Webmentions](https://indieweb.org/webmention) but the setup was quite complex. I want to add it later. | ||
|
||
Now the comments are raw calls to the mastodon context APIs. There is a slight technicality in updating the `tootId` in the post frontmatter, but when set it will fetch and render the comments on client side (so they will be latest). | ||
|
||
Old comments are available in the [old repo's issues](https://github.com/xypnox/blag_zola/issues). | ||
|
||
Earlier people needed a github account to post comments, now they need a mastodon/fediverse account instead. | ||
|
||
|
||
Here is the [basic Solid component](https://) I wrote for rendering comments: | ||
|
||
<CodeEmbed url="https://raw.githubusercontent.com/xypnox/xypnox.github.io/refs/heads/v2/src/theme.ts" lang="ts" /> | ||
|
||
And the code embed component (because why not): | ||
|
||
<CodeEmbed url="https://raw.githubusercontent.com/xypnox/xypnox.github.io/refs/heads/v2/src/theme.ts" lang="astro" /> | ||
|
||
Currently apart from the user profile image, the data is rendered in plain text, no icons. | ||
|
||
Also new is the css based syntax highlighting from github code blocks as seen above. | ||
|
||
With these changes, the site is now entirely customizable in terms of colors and fonts. The code blocks and comments were the last remaining parts that did not use the theme variables. | ||
|
||
|
||
|
||
Hopefully you will find comments below. |
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,31 +1,34 @@ | ||
import { z, defineCollection } from 'astro:content'; | ||
import { z, defineCollection } from "astro:content"; | ||
|
||
const blog = defineCollection({ | ||
schema: ({ image }) => z.object({ | ||
title: z.string(), | ||
date: z.date(), | ||
description: z.string().optional(), | ||
tags: z.array(z.string()).optional(), | ||
schema: ({ image }) => | ||
z.object({ | ||
title: z.string(), | ||
date: z.date(), | ||
description: z.string().optional(), | ||
tags: z.array(z.string()).optional(), | ||
|
||
categories: z.array(z.string()).optional(), | ||
categories: z.array(z.string()).optional(), | ||
|
||
// Image to show in blog list and intro image in blog post | ||
coverImage: image().optional(), | ||
coverAlt: z.string().optional(), | ||
socialImage: image().optional(), // will use coverImage or default | ||
hidden: z.boolean().optional(), // will default to false | ||
// Image to show in blog list and intro image in blog post | ||
coverImage: image().optional(), | ||
coverAlt: z.string().optional(), | ||
socialImage: image().optional(), // will use coverImage or default | ||
hidden: z.boolean().optional(), // will default to false | ||
|
||
hideTOC: z.boolean().optional(), // will default to false | ||
}), | ||
}) | ||
tootId: z.string().optional(), // to show the comments from mastodon toot | ||
|
||
const poems = defineCollection({ | ||
schema: () => z.object({ | ||
title: z.string(), | ||
date: z.date(), | ||
hidden: z.boolean().optional(), // will default to false | ||
}), | ||
}) | ||
hideTOC: z.boolean().optional(), // will default to false | ||
}), | ||
}); | ||
|
||
export const collections = { blog, poems } | ||
const poems = defineCollection({ | ||
schema: () => | ||
z.object({ | ||
title: z.string(), | ||
date: z.date(), | ||
hidden: z.boolean().optional(), // will default to false | ||
}), | ||
}); | ||
|
||
export const collections = { blog, poems }; |
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
Oops, something went wrong.