@respectify/astro 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/CommentList.astro +4 -3
- package/package.json +1 -1
- package/src/env.d.ts +23 -0
- package/src/schema.ts +14 -11
|
@@ -18,12 +18,13 @@ const { postSlug, apiPath = '/api/respectify/comments', enableDelete = false } =
|
|
|
18
18
|
<p class="rf-comments__empty rf-comments__hidden">No comments yet. Be the first to comment!</p>
|
|
19
19
|
</section>
|
|
20
20
|
|
|
21
|
-
<script
|
|
21
|
+
<script>
|
|
22
22
|
import { actions } from 'astro:actions';
|
|
23
23
|
import { fetchComments, renderCommentHtml } from '@respectify/astro/client';
|
|
24
24
|
|
|
25
25
|
async function checkAuthForDelete() {
|
|
26
|
-
|
|
26
|
+
const section = document.querySelector('.rf-comments__section');
|
|
27
|
+
if (section?.dataset.enableDelete !== 'true') return false;
|
|
27
28
|
try {
|
|
28
29
|
const response = await fetch('/api/auth-status');
|
|
29
30
|
if (!response.ok) return false;
|
|
@@ -74,7 +75,7 @@ const { postSlug, apiPath = '/api/respectify/comments', enableDelete = false } =
|
|
|
74
75
|
|
|
75
76
|
async function loadComments(section) {
|
|
76
77
|
const postSlug = section.dataset.postSlug || '';
|
|
77
|
-
const path = section.dataset.apiPath
|
|
78
|
+
const path = section.dataset.apiPath;
|
|
78
79
|
const loadingEl = section.querySelector('.rf-comments__loading');
|
|
79
80
|
const listEl = section.querySelector('.rf-comments__list');
|
|
80
81
|
const emptyEl = section.querySelector('.rf-comments__empty');
|
package/package.json
CHANGED
package/src/env.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="astro/client" />
|
|
2
|
+
|
|
3
|
+
import '@astrojs/db';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
namespace App {
|
|
7
|
+
interface Locals {
|
|
8
|
+
isAuthenticated?: boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module 'astro:env/server' {
|
|
14
|
+
export const RESPECTIFY_EMAIL: string;
|
|
15
|
+
export const RESPECTIFY_API_KEY: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare module 'astro:db' {
|
|
19
|
+
export const Comment: import('@astrojs/db/runtime').Table<
|
|
20
|
+
'Comment',
|
|
21
|
+
typeof import('./schema').RespectifyComment.columns
|
|
22
|
+
>;
|
|
23
|
+
}
|
package/src/schema.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { defineTable, column, NOW } from 'astro:db';
|
|
2
|
+
import type { TableConfig } from '@astrojs/db/types';
|
|
3
|
+
|
|
4
|
+
const respectifyCommentColumns = {
|
|
5
|
+
id: column.number({ primaryKey: true }),
|
|
6
|
+
postSlug: column.text(),
|
|
7
|
+
author: column.text(),
|
|
8
|
+
email: column.text({ optional: true }),
|
|
9
|
+
content: column.text(),
|
|
10
|
+
createdAt: column.date({ default: NOW }),
|
|
11
|
+
approved: column.boolean({ default: false }),
|
|
12
|
+
parentId: column.number({ optional: true }),
|
|
13
|
+
};
|
|
2
14
|
|
|
3
15
|
/** Astro DB table definition for Respectify comments. Merge into your db/config.ts. */
|
|
4
|
-
export const RespectifyComment = defineTable({
|
|
5
|
-
columns:
|
|
6
|
-
id: column.number({ primaryKey: true }),
|
|
7
|
-
postSlug: column.text(),
|
|
8
|
-
author: column.text(),
|
|
9
|
-
email: column.text({ optional: true }),
|
|
10
|
-
content: column.text(),
|
|
11
|
-
createdAt: column.date({ default: NOW }),
|
|
12
|
-
approved: column.boolean({ default: false }),
|
|
13
|
-
parentId: column.number({ optional: true }),
|
|
14
|
-
},
|
|
16
|
+
export const RespectifyComment: TableConfig<typeof respectifyCommentColumns> = defineTable({
|
|
17
|
+
columns: respectifyCommentColumns,
|
|
15
18
|
indexes: [
|
|
16
19
|
{ on: ['postSlug'], unique: false },
|
|
17
20
|
{ on: ['approved'], unique: false },
|