feat: allow custom excerpt

This commit is contained in:
EGOIST
2022-05-19 19:29:57 +08:00
parent 4bae50d28e
commit e7fa4d2f24
24 changed files with 262 additions and 346 deletions
+2 -2
View File
@@ -6,7 +6,7 @@ export const SitePage: React.FC<{
type: PageType
publishedAt: string
title: string
content: string
contentHTML: string
}
}> = ({ page }) => {
return (
@@ -25,7 +25,7 @@ export const SitePage: React.FC<{
</div>
<div
className="my-8 prose"
dangerouslySetInnerHTML={{ __html: page.content }}
dangerouslySetInnerHTML={{ __html: page.contentHTML }}
></div>
</>
)
+2 -1
View File
@@ -96,7 +96,8 @@ export const useEditor = ({
view.destroy()
setView(null)
}
}, [onChange, placeholder, onDropFile])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [placeholder, onDropFile])
// Update view state when `value` changed
useEffect(() => {
+27 -12
View File
@@ -1,22 +1,35 @@
import clsx from "clsx"
import { DetailedHTMLProps, forwardRef, InputHTMLAttributes } from "react"
import { forwardRef } from "react"
type Props = DetailedHTMLProps<
InputHTMLAttributes<HTMLInputElement>,
HTMLInputElement
> & {
type InputProps<TMultiline extends boolean> = {
label?: string
addon?: string
isBlock?: boolean
error?: string
help?: React.ReactNode
}
multiline?: TMultiline
} & React.ComponentPropsWithRef<TMultiline extends true ? "textarea" : "input">
export const Input = forwardRef<HTMLInputElement, Props>(function Input(
{ label, addon, className, isBlock, error, help, ...inputProps },
ref
export const Input = forwardRef(function Input<
TMutliline extends boolean = false
>(
{
label,
addon,
className,
isBlock,
error,
help,
multiline,
...inputProps
}: InputProps<TMutliline>,
ref: TMutliline extends true
? React.ForwardedRef<HTMLTextAreaElement>
: React.ForwardedRef<HTMLInputElement>
) {
const hasAddon = !!addon
const Component = (multiline ? "textarea" : "input") as any
return (
<div>
{label && (
@@ -25,9 +38,9 @@ export const Input = forwardRef<HTMLInputElement, Props>(function Input(
</label>
)}
<div className="flex items-center">
<input
<Component
{...inputProps}
ref={ref}
ref={ref as any}
className={clsx(
"input",
hasAddon && `has-addon`,
@@ -47,4 +60,6 @@ export const Input = forwardRef<HTMLInputElement, Props>(function Input(
)}
</div>
)
})
}) as <TMultiline extends boolean = false>(
props: InputProps<TMultiline>
) => JSX.Element