mirror of https://github.com/MaxLeiter/Drift
client/server: add post searching
parent
9949faeebd
commit
951088bacf
@ -1,4 +1,2 @@
|
||||
API_URL=http://localhost:3000
|
||||
WELCOME_TITLE="Welcome to Drift"
|
||||
WELCOME_CONTENT="## Drift is a self-hostable clone of GitHub Gist. \nIt is a simple way to share code and text snippets with your friends, with support for the following:\n \n - Render GitHub Extended Markdown (including images)\n - User authentication\n - Private, public, and password protected posts\n - Markdown is rendered and stored on the server\n - Syntax highlighting and automatic language detection\n - Drag-and-drop file uploading\n\n If you want to signup, you can join at [/signup](/signup) as long as you have a passcode provided by the administrator (which you don\\\'t need for this demo). **This demo is on a memory-only database, so accounts and pastes can be deleted at any time.** \n\nYou can find the source code on [GitHub](https://github.com/MaxLeiter/drift)."
|
||||
SECRET_KEY=secret
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
.textarea {
|
||||
height: 100%;
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
import ShiftBy from "@components/shift-by"
|
||||
import { Spacer, Tabs, Card, Textarea, Text } from "@geist-ui/core"
|
||||
import Image from 'next/image'
|
||||
import styles from './home.module.css'
|
||||
import markdownStyles from '@components/preview/preview.module.css'
|
||||
const Home = ({ introTitle, introContent, rendered }: {
|
||||
introTitle: string
|
||||
introContent: string
|
||||
rendered: string
|
||||
}) => {
|
||||
return (<><div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
||||
<ShiftBy y={-2}><Image src={'/assets/logo-optimized.svg'} width={'48px'} height={'48px'} alt="" /></ShiftBy>
|
||||
<Spacer />
|
||||
<Text style={{ display: 'inline' }} h1>{introTitle}</Text>
|
||||
</div>
|
||||
<Card>
|
||||
<Tabs initialValue={'preview'} hideDivider leftSpace={0}>
|
||||
<Tabs.Item label={"Raw"} value="edit">
|
||||
{/* <textarea className={styles.lineCounter} wrap='off' readOnly ref={lineNumberRef}>1.</textarea> */}
|
||||
<div style={{ marginTop: 'var(--gap-half)', display: 'flex', flexDirection: 'column' }}>
|
||||
<Textarea
|
||||
readOnly
|
||||
value={introContent}
|
||||
width="100%"
|
||||
// TODO: Textarea should grow to fill parent if height == 100%
|
||||
style={{ flex: 1, minHeight: 350 }}
|
||||
resize="vertical"
|
||||
className={styles.textarea}
|
||||
/>
|
||||
</div>
|
||||
</Tabs.Item>
|
||||
<Tabs.Item label="Preview" value="preview">
|
||||
<div style={{ marginTop: 'var(--gap-half)', }}>
|
||||
<article className={markdownStyles.markdownPreview} dangerouslySetInnerHTML={{ __html: rendered }} style={{
|
||||
height: "100%"
|
||||
}} />
|
||||
</div>
|
||||
</Tabs.Item>
|
||||
</Tabs>
|
||||
</Card></>)
|
||||
}
|
||||
|
||||
export default Home
|
||||
@ -1,7 +1,13 @@
|
||||
import type { Post } from "@lib/types"
|
||||
import PostList from "../post-list"
|
||||
|
||||
const MyPosts = ({ posts, error }: { posts: any, error: any }) => {
|
||||
return <PostList posts={posts} error={error} />
|
||||
const MyPosts = ({ posts, error, morePosts }:
|
||||
{
|
||||
posts: Post[],
|
||||
error: boolean,
|
||||
morePosts: boolean
|
||||
}) => {
|
||||
return <PostList morePosts={morePosts} initialPosts={posts} error={error} />
|
||||
}
|
||||
|
||||
export default MyPosts
|
||||
|
||||
@ -1,30 +1,41 @@
|
||||
import * as express from "express"
|
||||
import * as bodyParser from "body-parser"
|
||||
import * as errorhandler from "strong-error-handler"
|
||||
import * as cors from "cors"
|
||||
import { posts, users, auth, files } from "@routes/index"
|
||||
import { errors } from "celebrate"
|
||||
import secretKey from "@lib/middleware/secret-key"
|
||||
import markdown from "@lib/render-markdown"
|
||||
|
||||
export const app = express()
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: true }))
|
||||
app.use(bodyParser.json({ limit: "5mb" }))
|
||||
|
||||
const corsOptions = {
|
||||
origin: `http://localhost:3001`
|
||||
}
|
||||
app.use(cors(corsOptions))
|
||||
|
||||
app.use("/auth", auth)
|
||||
app.use("/posts", posts)
|
||||
app.use("/users", users)
|
||||
app.use("/files", files)
|
||||
|
||||
app.get('/welcome', secretKey, (req, res) => {
|
||||
const introContent = process.env.WELCOME_CONTENT;
|
||||
const introTitle = process.env.WELCOME_TITLE;
|
||||
|
||||
if (!introContent || !introTitle) {
|
||||
return res.status(500).json({ error: 'Missing welcome content' });
|
||||
}
|
||||
|
||||
return res.json({
|
||||
title: introTitle,
|
||||
content: introContent,
|
||||
rendered: markdown(introContent)
|
||||
});
|
||||
})
|
||||
|
||||
app.use(errors())
|
||||
|
||||
app.use(
|
||||
errorhandler({
|
||||
debug: process.env.ENV !== "production",
|
||||
log: true
|
||||
})
|
||||
errorhandler({
|
||||
debug: process.env.ENV !== "production",
|
||||
log: true
|
||||
})
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue