From b86dda189d5cda14a0ce41fe977a8573b2d6d992 Mon Sep 17 00:00:00 2001
From: pfqgauxfb <3521106529@qq.com>
Date: Tue, 3 Jun 2025 09:25:38 +0800
Subject: [PATCH] feng
---
src/components/Comments/index.js | 97 ++++++++++++++++++
src/components/Comments/styles.module.css | 114 ++++++++++++++++++++++
src/theme/DocItem/index.js | 61 ++++++++++++
src/theme/DocItem/styles.module.css | 19 ++++
4 files changed, 291 insertions(+)
create mode 100644 src/components/Comments/index.js
create mode 100644 src/components/Comments/styles.module.css
create mode 100644 src/theme/DocItem/index.js
create mode 100644 src/theme/DocItem/styles.module.css
diff --git a/src/components/Comments/index.js b/src/components/Comments/index.js
new file mode 100644
index 0000000..fbf44c9
--- /dev/null
+++ b/src/components/Comments/index.js
@@ -0,0 +1,97 @@
+import React, { useState, useEffect } from 'react';
+import styles from './styles.module.css';
+
+const Comments = () => {
+ const [comments, setComments] = useState([]);
+ const [newComment, setNewComment] = useState('');
+ const [name, setName] = useState('');
+
+ // 从 localStorage 加载评论
+ useEffect(() => {
+ const savedComments = localStorage.getItem('docComments');
+ if (savedComments) {
+ setComments(JSON.parse(savedComments));
+ }
+ }, []);
+
+ // 保存评论到 localStorage
+ const saveComments = (newComments) => {
+ localStorage.setItem('docComments', JSON.stringify(newComments));
+ };
+
+ const handleSubmit = (e) => {
+ e.preventDefault();
+ if (!newComment.trim() || !name.trim()) return;
+
+ const comment = {
+ id: Date.now(),
+ name,
+ content: newComment,
+ date: new Date().toLocaleString(),
+ };
+
+ const updatedComments = [...comments, comment];
+ setComments(updatedComments);
+ saveComments(updatedComments);
+ setNewComment('');
+ };
+
+ const handleDelete = (commentId) => {
+ const updatedComments = comments.filter(comment => comment.id !== commentId);
+ setComments(updatedComments);
+ saveComments(updatedComments);
+ };
+
+ return (
+
+
评论
+
+
+
+
+ {comments.map((comment) => (
+
+
+
{comment.name}
+
+ {comment.date}
+
+
+
+
{comment.content}
+
+ ))}
+
+
+ );
+};
+
+export default Comments;
\ No newline at end of file
diff --git a/src/components/Comments/styles.module.css b/src/components/Comments/styles.module.css
new file mode 100644
index 0000000..1b3e660
--- /dev/null
+++ b/src/components/Comments/styles.module.css
@@ -0,0 +1,114 @@
+.commentsContainer {
+ margin: 2rem 0;
+ padding: 1rem;
+ border-radius: 8px;
+ background-color: var(--ifm-background-color);
+}
+
+.title {
+ font-size: 1.5rem;
+ margin-bottom: 1.5rem;
+ color: var(--ifm-color-primary);
+}
+
+.form {
+ margin-bottom: 2rem;
+}
+
+.inputGroup {
+ margin-bottom: 1rem;
+}
+
+.input,
+.textarea {
+ width: 100%;
+ padding: 0.75rem;
+ border: 1px solid var(--ifm-color-emphasis-300);
+ border-radius: 4px;
+ background-color: var(--ifm-background-color);
+ color: var(--ifm-color-emphasis-900);
+ font-size: 1rem;
+ transition: border-color 0.2s ease;
+}
+
+.input:focus,
+.textarea:focus {
+ outline: none;
+ border-color: var(--ifm-color-primary);
+}
+
+.textarea {
+ min-height: 100px;
+ resize: vertical;
+}
+
+.submitButton {
+ padding: 0.75rem 1.5rem;
+ background-color: var(--ifm-color-primary);
+ color: white;
+ border: none;
+ border-radius: 4px;
+ font-size: 1rem;
+ cursor: pointer;
+ transition: background-color 0.2s ease;
+}
+
+.submitButton:hover {
+ background-color: var(--ifm-color-primary-darker);
+}
+
+.commentsList {
+ margin-top: 2rem;
+}
+
+.comment {
+ padding: 1rem;
+ margin-bottom: 1rem;
+ border: 1px solid var(--ifm-color-emphasis-300);
+ border-radius: 4px;
+ background-color: var(--ifm-background-color);
+}
+
+.commentHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 0.5rem;
+}
+
+.commentName {
+ font-weight: bold;
+ color: var(--ifm-color-primary);
+}
+
+.commentActions {
+ display: flex;
+ align-items: center;
+ gap: 1rem;
+}
+
+.commentDate {
+ font-size: 0.875rem;
+ color: var(--ifm-color-emphasis-600);
+}
+
+.deleteButton {
+ padding: 0.25rem 0.5rem;
+ background-color: var(--ifm-color-danger);
+ color: white;
+ border: none;
+ border-radius: 4px;
+ font-size: 0.875rem;
+ cursor: pointer;
+ transition: background-color 0.2s ease;
+}
+
+.deleteButton:hover {
+ background-color: var(--ifm-color-danger-darker);
+}
+
+.commentContent {
+ margin: 0;
+ line-height: 1.5;
+ color: var(--ifm-color-emphasis-900);
+}
\ No newline at end of file
diff --git a/src/theme/DocItem/index.js b/src/theme/DocItem/index.js
new file mode 100644
index 0000000..6183c19
--- /dev/null
+++ b/src/theme/DocItem/index.js
@@ -0,0 +1,61 @@
+import React from 'react';
+import clsx from 'clsx';
+import {useDoc} from '@docusaurus/theme-common/internal';
+import DocItemContent from '@theme-original/DocItem/Content';
+import DocItemFooter from '@theme-original/DocItem/Footer';
+import DocItemPaginator from '@theme-original/DocItem/Paginator';
+import DocItemTOCMobile from '@theme-original/DocItem/TOC/Mobile';
+import DocItemTOCDesktop from '@theme-original/DocItem/TOC/Desktop';
+import DocVersionBadge from '@theme-original/DocVersionBadge';
+import DocVersionBanner from '@theme-original/DocVersionBanner';
+import DocItemLocalTOC from '@theme-original/DocItem/LocalTOC';
+import DocBreadcrumbs from '@theme-original/DocBreadcrumbs';
+import styles from './styles.module.css';
+import Comments from '@site/src/components/Comments';
+
+export default function DocItem(props) {
+ const {metadata, frontMatter, assets} = useDoc();
+ const {
+ hide_table_of_contents: hideTableOfContents,
+ toc_min_heading_level: tocMinHeadingLevel,
+ toc_max_heading_level: tocMaxHeadingLevel,
+ } = frontMatter;
+ const {hide_comment_section: hideCommentSection} = frontMatter;
+
+ return (
+
+
+
+
+
+
+
+
+
+
+ {!hideCommentSection && }
+
+
+
+
+
+ {!hideTableOfContents && props.toc && (
+
+
+
+ )}
+
+ );
+}
\ No newline at end of file
diff --git a/src/theme/DocItem/styles.module.css b/src/theme/DocItem/styles.module.css
new file mode 100644
index 0000000..0d10161
--- /dev/null
+++ b/src/theme/DocItem/styles.module.css
@@ -0,0 +1,19 @@
+.docItemContainer {
+ margin: 0 auto;
+ padding: 0 1rem;
+}
+
+.docItemCol {
+ flex: 1 0 75%;
+ max-width: 75%;
+}
+
+.docItemMain {
+ flex: 1 0 auto;
+}
+
+@media (max-width: 996px) {
+ .docItemCol {
+ max-width: 100%;
+ }
+}
\ No newline at end of file