You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And in hexo/index.ts I exports some API to be used in getStaticPaths and getStaticProps:
importHexofrom'hexo';lethexo=null;constinit=async()=>{// This only needs to be initiated onceif(!hexo){hexo=newHexo(process.cwd(),{});awaithexo.init();// Load hexo's config and pluginsawaithexo.load();// Load hexo's local cache and dataconsole.log('load hexo!')}returnhexo;};exportconstgetPosts=async()=>{awaitinit();constposts=hexo.locals.get('posts').sort('-date').toArray();returnposts.map(post=>({params: {id: post.path.replace('post/','').replace(/\/$/,'')}}));};exportconstfindPostById=async(id)=>{awaitinit();returnhexo.locals.get('posts').findOne({path: `post/${id}/`});};
And in pages/post/[id].tsx I import hexo/index.tsx:
However, when I run npx next build, I notice load hexo! showed up more than once. It shows up on Collecting page data, and every static post page being generated (Generating static pages).
Anyone can help me with that?
Update
OK, I have some clue. I add console.log(process.pid, process.ppid); to hexo/index.ts. And then I realize Next.js use multi-thread to speed up getStaticPaths and getStaticProps (they usually involve requesting an external API endpoint or querying a database, which can be slow). However, in my case, I only need one instance across all pages. How can I disable the multi-thread, or does Next.js supports sharing an instance across different pages?
Update
How can I disable the multi-thread, or does Next.js supports sharing an instance across different pages?
After taking a look at the source code of Next.js, it is impossible. A feature request has been issued: #33015
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to intergrare [Hexo] into a Next.js project. Although Hexo itself is a known SSG, its APIs make it can be used as a CMS, too.
So I start a project like this:
And in
hexo/index.ts
I exports some API to be used ingetStaticPaths
andgetStaticProps
:And in
pages/post/[id].tsx
I importhexo/index.tsx
:However, when I run
npx next build
, I noticeload hexo!
showed up more than once. It shows up onCollecting page data
, and every static post page being generated (Generating static pages
).Anyone can help me with that?
Update
OK, I have some clue. I add
console.log(process.pid, process.ppid);
tohexo/index.ts
. And then I realize Next.js use multi-thread to speed upgetStaticPaths
andgetStaticProps
(they usually involve requesting an external API endpoint or querying a database, which can be slow). However, in my case, I only need one instance across all pages. How can I disable the multi-thread, or does Next.js supports sharing an instance across different pages?Update
After taking a look at the source code of Next.js, it is impossible. A feature request has been issued: #33015
Beta Was this translation helpful? Give feedback.
All reactions