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
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
タクシーアプリ『GO』の実践的データ活用
mot_techtalk
3
190
AI駆動開発を通して感じた、 AI時代のデザイナーの役割変化
whisaiyo
0
190
Snowflakeと仲良くなる第一歩
coco_se
4
410
作って終わりにしない タイミーのセマンティックレイヤー育成の現在地
chanyou0311
3
2.1k
自律型AIエージェントは何を破壊するのか
kojira
0
150
実装は速くなった、レビューはどうする? ― 自身のレビューをAIで再現させるサーヴァントエンジニアリングのすゝめ / Implementation got faster. So what about reviews? — An invitation to Servant Engineering: Recreating your own code reviews with AI
nrslib
8
4.6k
Building applications in the Gemini API family.
line_developers_tw
PRO
0
2.8k
2026.06.13_AI時代に事業会社が「SIer出身エンジニア」を求める理由 / Why Businesses Seek Engineers with a System Integrator Background in the AI Era
jumtech
0
1k
AI Engineering Summit Tokyo 2026 AIの前に、やることがある 〜医療データ企業の4フェーズ〜
dtaniwaki
0
2.5k
AIの性能が向上しても未解決な組織の重大問題は何か?/An Unsolved Organizational Problem in the Age of AI
moriyuya
3
600
LLMと共に進化するプロセスを目指して
ymatsuwitter
12
3.9k
【Cyber-sec+】経営層を"動かす"ための考え方
hssh2_bin
0
120
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
Building Adaptive Systems
keathley
44
3k
Facilitating Awesome Meetings
lara
57
7k
The Curse of the Amulet
leimatthew05
1
13k
Technical Leadership for Architectural Decision Making
baasie
3
400
It's Worth the Effort
3n
188
29k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Paper Plane (Part 1)
katiecoart
PRO
0
8.8k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
250
Site-Speed That Sticks
csswizardry
13
1.2k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
160
Utilizing Notion as your number one productivity tool
mfonobong
4
320
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実装- なんとか要件通りに機能しました。
ありがとうございました。