-
-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(SSG): Add isSSG
and isSSR
API
#2033
Conversation
Thanks, I think PR should be for v4. |
Sorry, I mistook, it is second time. |
I'm checking about this PR. I have one question for you. Are you referring to other frameworks, such as Astro or Svelte, for these features? |
No, I'm not. But this idea is from Astro and Svelte. In Astro, you can switch SSR/SSG: ---
export const prerender = true // SSG
---
<h1>Static Page</h1> ---
export const prerender = false // SSR
---
<h1>{ Math.random() }</h1> Or, you can set config file default: // astro.config.ts
import { defineConfig } from 'astro'
export default defineConfig({
output: 'server', // Default is SSR
// output: 'hybrid', // Default is SSG
// output: 'static' // All SSG
}) If you use Astro, you create a file for each route. Hono isn't so. So I added |
Sorry that I suggested the name, but maybe server/static is more familiar and cooler than SSR/SSG! Let's leave the name on this ticket and talk about it here. |
As for |
I'm not familiar with English. So I can't decide which is better |
Hey @nakasyou ! Please wait a moment for this PR review and merge. I'm actually using it and testing its use. |
Hi @nakasyou and @watany-dev Sorry for the late reply. I have been considering about this
app.get('/api', doNotSSG(), (c) => {
return c.json(0)
}) What do you think about it? |
As you say, I think we don't need two middlewares. How about a middleware Interface like This time, we will create a prerender or ssg option, and add swr (stale-while-revalidate) or spa (
// Follows the default of toSSG.
app.get('/ssg/1', (c) => {
return c.html('ssg1')
})
// If ssg: undefined, it follows the default of toSSG.
app.get('/ssg/2', defineRender(), (c) => {
return c.html('ssg2')
})
app.get('/ssg/3', defineRender(ssg: true), (c) => {
return c.html('ssg3')
})
app.get('/ssr', defineRender(ssg: false), (c) => {
return c.html('ssr')
})
// SSG:
// ./static/ssg/1.html
// ./static/ssg/2.html
// ./static/ssg/3.html
toSSG(app, fs)
// Follows the default of toSSG.
app.get('/ssg/1', (c) => {
return c.html('ssg1')
})
// If ssg: undefined, it follows the default of toSSG.
app.get('/ssg/2', defineRender(), (c) => {
return c.html('ssg2')
})
app.get('/ssg/3', defineRender(ssg: true), (c) => {
return c.html('ssg3')
})
app.get('/ssr', defineRender(ssg: false), (c) => {
return c.html('ssr')
})
// SSG:
// ./static/ssg/3.html
toSSG(app, fs, {
defaultSSG: false // default true
}) |
Hi @yusukebe @watany-dev, thank you for reviewing. It is very smart, and it's customizable.
I don't think for that. So I don't think SSG should always be the default, and @watany-dev 's idea is better. |
Hi @nakasyou and @watany-dev How about #2104 ? |
Hi @yusukebe
I think we can write this code. app.use('*', disableSSG())
app.get('/', c => c.json('Hello world!')) This code is like SSR-Based mode. I think this is cool. |
I added
isSSG
andisSSR
API to SSG helper.You can switch SSG/SSR if you merge.
Examples
SSG-Based mode (default is
undefined
)SSG-Based mode (default is
ssg
)SSR-Based mode (default is
ssr
)Author should do the followings, if applicable
yarn denoify
to generate files for Deno