Skip to content

Commit

Permalink
getPageHead
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Jul 26, 2022
1 parent 5bd063c commit 96b0832
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/example/src/repo/issues/@issueId.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default defineVilay<{
<div className="flex flex-grow flex-row w-full">
<div className="flex-column w-3/4 flex-grow">
<article
className="w-full prose lg:prose-l markdown-body dark:bg-dark"
className="w-full prose lg:prose-l markdown-body dark:bg-dark min-h-6"
dangerouslySetInnerHTML={{
// __html: repository.issue.bodyHTML,
__html: repository.issue.bodyHTML,
Expand Down
12 changes: 7 additions & 5 deletions packages/example/src/repo/pulls/@pullId.page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { graphql, usePreloadedQuery, type PreloadedQuery } from 'react-relay'
import { defineVilay } from 'vilay'
import { defineVilay, usePageContext } from 'vilay'
import defaultDefines from '../../lib/renderer/_default.page'
import type {
PullIdByRepoQuery,
Expand Down Expand Up @@ -81,6 +81,8 @@ export default defineVilay<{
}),
// Relay pagination example.
Page: ({ queryRef }) => {
const context = usePageContext()
console.log({context})
const { repository } = usePreloadedQuery<PullIdByRepoQuery>(query, queryRef)
const nameWithOwner = `${queryRef.variables.owner}/${queryRef.variables.name}`
const pr = repository?.pullRequest
Expand Down Expand Up @@ -115,7 +117,7 @@ export default defineVilay<{
<div className="flex flex-row">
<div className="flex-column w-3/4 flex-grow">
<article
className="w-full prose lg:prose-l markdown-body dark:bg-dark"
className="w-full prose lg:prose-l markdown-body dark:bg-dark min-h-64"
dangerouslySetInnerHTML={{
// __html: repository.issue.bodyHTML,
__html: repository.pullRequest.bodyHTML,
Expand All @@ -136,10 +138,10 @@ export default defineVilay<{
</p>

{pr?.labels?.nodes?.length > 0 && (
<p className="text-xs">
<div>
<h3 className="text-l">Labels</h3>
<Labels labels={pr?.labels?.nodes} />
</p>
<Labels size='xs' labels={pr?.labels?.nodes} />
</div>
)}

</div>
Expand Down
8 changes: 6 additions & 2 deletions packages/example/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ body.dark {
}

.prose {
max-width: fit-content;
width: 80ch;
/* /* max-width: fit-content; */
max-width: 80ch;
/* width: 100%; */
}


.w-prose {
max-width: 80ch;
}

.markdown-body {
padding: 6px
}
Expand Down
2 changes: 1 addition & 1 deletion packages/render/cloudflare/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function render(req: Request, renderVps: typeof renderPage) {
return null
} else {
const { contentType, statusCode } = httpResponse
return new Response(httpResponse.getWebStream(), {
return new Response(httpResponse.getReadableWebStream(), {
status: statusCode,
headers: {
'Content-Type': `${contentType};charset=utf-8`,
Expand Down
1 change: 1 addition & 0 deletions packages/vilay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"h3": "^0.5.3",
"listhen": "^0.2.6",
"serve-static": "^1.15.0",
"ua-parser-js": "^1.0.2",
"undici": "^5.1.1",
"vite": "^2.9.6",
"vite-plugin-ssr": "^0.4.11",
Expand Down
6 changes: 4 additions & 2 deletions packages/vilay/server/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export async function createServer(root: string) {
const app = createApp({ onError })

app.use(serveStatic(join(root, 'dist', 'client')))
app.use((req, res, next) => {
app.use(async (req, res, next) => {
if (req.method !== 'GET') return next()
if (req.url == null) return next(new Error('url is null'))
const userAgent = req.headers['user-agent']

const pageContextInit = {
url: req.url,
cookies: useCookies(req),
userAgent: req.headers['user-agent'],
userAgent,
fetch,
}
renderPage<PageContext, typeof pageContextInit>(pageContextInit).then(
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 96b0832

Please sign in to comment.