Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装-
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
minamitakao
October 28, 2021
Technology
1.2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装-
minamitakao
October 28, 2021
More Decks by minamitakao
See All by minamitakao
Next.jsとWordPressで 初めてのフロントエンジニア体験記。
minamitakao
1
1.1k
Other Decks in Technology
See All in Technology
Android の公式 Skill / Android skills
yanzm
0
120
新規事業を牽引する技術選定 〜フルスタックTypeScript開発の実践事例〜
nullnull
3
380
RAG を使わないという選択肢
tatsutaka
1
150
日本 Fintech 未来予測レポート 2027〜2028年(オリジナル版)
8maki
0
1.3k
AIソロプレナー時代に2ヶ月で20人増員した事業創造会社の開発組織の話
miyatakoji
0
570
失敗を経て、Harness Engineering で 大切にしたいことを考える / Learning from Failure: What Matters in Harness Engineering
bitkey
PRO
1
290
Microsoft Build Keynoteふりかえり
tomokusaba
0
120
価格.comをAI駆動で全面刷新する ー 30年分の技術的負債を返し、次の30年の土台をつくる ー / AI Engineering Summit Tokyo 2026
tkyowa
53
59k
データサイエンスを価値につなげるプロジェクト設計 〜 DS一年目が現場で得た気づき 〜
ysd113
1
150
小さくはじめるSLI/SLO ~育てながら組織に定着させる実践知~ / Starting Small with SLI/SLOs: Building Adoption Through Continuous Growth
nari_ex
3
1.4k
FinOps × AIエージェントで実現する コストインシデントの自動調査
oasis1994liveforever
0
110
中期計画、2回作ってみた ~業務委託と正社員、両方の視点から~
demaecan
1
650
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
160
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Un-Boring Meetings
codingconduct
0
310
Embracing the Ebb and Flow
colly
88
5.1k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
200
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
140
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Music & Morning Musume
bryan
47
7.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
200
Transcript
Next.jsとWordPressで 初めてのJamstack体験記 -Pagination実装- 2021.10.28 ジャムジャム!!Jamstack_ 【初⼼者歓迎LT会 @minamitakao_web
15年間サラリーマンでキャリアを積み上げ 2021年9⽉独⽴。 #駆け出しの フリーランス コーダー マネージャー Webデザイナー ⾃⼰紹介 Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装-
南貴夫(みなみたかお) 2男‧1⼥のお⽗ちゃんです。⼦供達との時間が⼀番の幸せです。 @minamitakao_web mono_croom mono_croom https://cwt.jp
作ってみてた Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- https://cwt.jp Webサイトの採⽤技術に フォーカスしたギャラリーサイト
WordPress側の実装 Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- 「WPGraphQL Offset Pagination」プラグインを追加 https://github.com/valu-digital/wp-graphql-offset-pagination できればこのプラグインは使うべきではありません。 wp-graphql コアのカーソルはより⾼速で効率的です
が、このプラグインは伝統的な WordPress のページ ネーション実装と⽐較して性能を発揮するはずです。 https://www.wpgraphql.com/ / / /forward-and-backward-pagination-with-wpgraphql/ ▪Forward and Backward Pagination with WPGraphQL 宿題:下記を参考にWP GraphQLのコア機能を使った実装に切り替えする。
Next.js側の実装について Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- export const getStaticPaths = async() => {
const pagesinfo = await getAllPagenations() let paths = []; let pagetotal = Math.floor(pagesinfo.total / PageSplit) if( pagesinfo.total % PageSplit > ) { pagetotal++; } for(let i= ;i<pagetotal;i++) { paths.push(`/page/${i}`) } return { paths, fallback: true, } } export const getAllPagenations = async()=> { const data = await fetchAPI(` { posts(first: ) { pageInfo { offsetPagination { total } } } } `) return data?.posts.pageInfo.offsetPagination } /pages/page/[num].jsx /lib/api.jsx 総ページ数を問い合わせます。 総ページ数を分割数で割って必要になるパスの情報を返します。
Next.js側の実装について Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- export const getStaticProps = async({params}) => {
const { num } = params; if(num < ) return { notFound: true } const res = await getPagesPosts(num); const allPosts = res.posts; if(allPosts.edges.length< ) return { notFound: true } return { props: { allPosts, categories: res.categories, num } } } /pages/page/[num].jsx
Next.js側の実装について Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- export const getPagesPosts = async(num) => {
const data = await fetchAPI(`query PostsByPages($offset: Int, $size: Int) { posts(where: {offsetPagination: {offset: $offset, size: $size}}) { edges {(略)} pageInfo { offsetPagination { hasMore hasPrevious total } } } }`,{ variables:{ offset: (num - ) * PageSplit, size: PageSplit } }); return data; } /lib/api.jsx 記事01 記事02 記事03 記事04 記事05 記事06 記事07 記事08 記事09 記事10 記事11 記事12 記事13 記事14 記事15 記事16 記事17 記事18 offset: offset: num: size: size: num: (num- )* (num- )*
Next.js側の実装について Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- /components/pagenatoin.jsx 実装イメージ:8個並ぶ 5以降は1から順に消えて数字の⼤きい⽅が1つ増える < > < >
< > 固定値 パラメーターnumから設定。 カレントの番号から順に設定
Next.js側の実装について Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- /components/pagenatoin.jsx splitpoint 中央値 [ , , ,
, , , , ] 準備配列 num カレントページ番号 val 準備配列の各数値 num = num - splitpoint 変化量 をそれぞれに適⽤して求める
Next.js側の実装について Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- /components/pagenatoin.jsx splitpoint 中央値 [ , , ,
, , , , ] 準備配列 num カレントページ番号 val 準備配列の各数値 val + ( num - splitpoint) num =
Next.js側の実装について Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- /components/pagenatoin.jsx - 最⼤値からはみ出た 分だけ準備関数を ずらしてみる ( (num
- splitpoint) - ((newnum - lastnum)- ) ) splitpoint 中央値 newnum 準備配列をもとに 求めた数値 num カレントページ番号 lastnum 最⼤値
Next.js側の実装について Next.jsとWordPressで初めてのJamstack体験記 -Pagination実装- なんとか要件通りに機能しました。
ありがとうございました。