Share
Embed
個人ブログを Next.js + Headless WordPressに 切り替えた話 / shifter-meetup-202011
Hidetaka Okamoto
November 04, 2020
Transcript
40 slides
-
ݸਓϒϩάΛ Next.js + Headless WordPressʹ Γସ͑ͨ S h i f
t e r M e e t u p 2 0 2 0 / 1 1 /4 -
Agenda • Why do I make my blog using Headless
WP with Next.js • How did I made it • Why do we make a website using Headless WP -
Agenda • Why do I make my blog using Headless
WP with Next.js • How did I made it • Why do we make a website using Headless WP -
WP-Kyoto • 5΄Ͳଓ͚͍ͯΔݸਓϒϩά࣮݉ݧ • EC2(t3.micro)Λ1ʙ2ಈ͔ͤΔఔͷΞΫηεɾऩӹ͋Δ • 2ʙ3લ͔ΒͣͬͱHeadless • WP ->
React SPA -> React SSG (Next.js) • ͍Ζ͍ΖࡶͳͷͰίʔυ͍͍ͩͨprivate -
Generic WordPress is 1 or 2 Tier application • View
/ AppϨΠϠʔ + DBϨΠϠʔ • AppͰো͕ى͖ΔͱɺViewר͖ࠐ·ΕΔ • ʮϓϥάΠϯߋ৽ͨ͠Βਅͬനʹͳͬͨʂʯ • ؾܰʹ࣮ݧ͢ΔαΠτͰোΛڪΕΔͷຊస -
Headless WordPress is 3 Tier application • View ϨΠϠʔ +
AppϨΠϠʔ + DBϨΠϠʔ • Appʹґଘ͠ͳ͍ViewΛ࡞Εɺޙํͷোʹר͖ࠐ·Εͳ͍ • SSGͳΒϏϧυ࣌ + AjaxͰ͔͠Appʹͭͳ͕ͳ͍ • ʮߋ৽Ͱ͖ͳͯ͘ɺݱঢ়ҡ࣋Ͱ͖Δঢ়ଶʯͷ -
Run SSG in Netlify with webhook • JAMstack DeploymentϓϥάΠϯͰهࣄߋ৽࣌ʹWebhook࣮ߦ •
Netlify͕GitHubʹ͋Διʔεʢmain branch)Λऔಘͯ͠Ϗϧυ • git push origin main / PR merge࣌ʹϏϧυ͕࣮ߦ͞ΕΔ • WP ThemeΛGitཧ͍ͯ͠Δ࣌ͱ͋·ΓมΘΒͳ͍ • ө·Ͱϥά͋ΔͷͰɺׂͦ͜ΓΔ -
Run SSG in Netlify with webhook is better? • هࣄߋ৽ͷʹϏϧυ͕ΔͷͰɺ࿈ଓߋ৽࣌ʹͪΐͬͱ͏͍͟
• NetlifyCircle CIͳͲϏϧυ࣌ؒʹ੍ݶ͕͋Δ • ෆඞཁͳϏϧυ͕ଟ͍ͳΒɺWebhook࣮ߦΛखಈԽ͖͔͢ • ·ͨNetlify / Circle CI / AWS / GCPͳͲΛࡳଋͰԥΖ͏ -
Headless WordPress for personal blog • WP͕ࣄނͬͯαΠτ͕མͪͳ͍ͷ͕Headless WP • WP͔ΒϏϧυWebhookΛ࣮ߦ͢Δඞཁ͕͋Δ
• ݟͨͱதΛݸผ(Git / WP)ཧͰ͖ΔͷͰɺ߹͏ਓʹ߹͏ -
Agenda • Why do I make my blog using Headless
WP with Next.js • How did I made it • Why do we make a website using Headless WP -
Next.js or Gatsby (Similar to Nuxt.js or Gridsome) • Gatsby(Gridsome)੩తαΠτੜ͕ϝΠϯ
• Next.js(Nuxt.js)ϑϧελοΫͰɺSSRAPI࡞Մೳ • σʔλऔಘॲཧ / ϧʔςΟϯά / ϓϥάΠϯʹେ͖Ίͷ͕ࠩ͋Δ • WPͩͱɺςʔϚ࡞_s͔SageͲ͔ͬͪͭ͏ʁʹ͍͔ۙ -
WordPress for Headless WP • ͍Ζ͍ΖׂΓͬͨӡ༻ʹͳΔ • ύʔϚϦϯΫ / ϓϨϏϡʔ
/ ςʔϚػೳ์غ • WP API / Block Editor / Build / ଟݴޠԽͷͨΊͷϓϥάΠϯબఆ • ϑϧϚωʔδυϗεςΟϯάΛͬͯAPI as a Serviceʹ͠Α͏ -
How to make a Headless WordPress site • WordPressʮཧը໘͖APIαʔόʔʯͩͱׂΓΔ •
React or VueɺGatsby(Gridsome) or Next.js(Nuxt.js)Έ -> σʔλιʔε͕ෳͳΒGraphQL͕͑ΔGatsbyͷํ͕Α͍͔ • WP ThemeΛϑϧεΫϥονͰ࡞Δʹ͍ۙײ֮ • ޙʑ͠ΜͲ͍ͷͰɺؤுͬͯTypeScriptΖ͏ -
Agenda • Why do I make my blog using Headless
WP with Next.js • How did I made it • Why do we make a website using Headless WP -
Case: Bootstrap with WordPress … <link href="css/bootstrap.min.css" rel="stylesheet"> </head> <body
<?php body_class(); ?> <div class="jumbotron"> <h1>Hello, world!</h1> <p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a></p> </div> <div class="row"> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> </div> -
Case: Bootstrap with React import React from 'react'; import {
Jumbotron, Button, Row, Col } from 'reactstrap'; export const App: FC = () => ( <> <Jumbotron> <h1>Hello, world!</h1> <p className="lead"><Button color="primary">Learn More</Button></p> </Jumbotron> <Row> <Col md={1}>.col</Col> </Row> </> ) -
Case: Bootstrap with WordPress … <link href="css/bootstrap.min.css" rel="stylesheet"> </head> <body
<?php body_class(); ?> <div class="jumbotron"> <h1>Hello, world!</h1> <p> <a class="btn btn-primary btn-lg” role="button">Learn more</a> </p> </div> <div class="row"> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> </div> import React from 'react'; import { Jumbotron, Button, Row, Col } from 'reactstrap'; export const App: FC = () => ( <> <Jumbotron> <h1>Hello, world!</h1> <p className=“lead”> <Button color="primary">Learn More</Button> </p> </Jumbotron> <Row> <Col md={1}>.col</Col> </Row> </> ) -
JS Frontend framework can IMPORT components • WordPress ThemeͰɺϚʔΫΞοϓͷίϐϖ͕ඞཁͩͬͨ •
ReactͳͲͰɺComponentͷImportͰར༻Ͱ͖Δ • ࣗࣾͷUIίϯϙʔωϯτूΛϥΠϒϥϦԽ͢Δ͜ͱͰɺ ෳͷϓϩδΣΫτͰϚʔΫΞοϓ / CSSΛ࠶ར༻Ͱ͖Δ -
D e s i g n s y s t
e m s f o r c o m p a n y o r S a a S • Google: Material Design • Twitter: Bootstarp • Alibaba: Ant Design • AWS: NorthStar • Digitalcube: Galaxy -
W P T h e m e • HTML /
JS / CSS / PHP / SQL • Componentεχϖοτͷίϐϖ • σϓϩΠࣗಈԽ͕ͪΐͬͱखؒ • طଘͷςʔϚΛར༻Ͱ͖Δ • ͦͦຖճ࡞Δඞཁͳ͍ J A M s t a c k F ro n t e n d • HTML / CSS / JavaScript / JS and JS • ComponentimportͰ࠶ར༻ • ΫϦοΫͰࣗಈσϓϩΠઃఆՄ • طଘͷςʔϚ͕ͦͦͳ͍ʹ͍ۙ • جຊతʹຖճεΫϥον -
Headless WordPress͕͍͍ͯΔͱࢥ͏݅ • ϑϧεΫϥονͰαΠτΛߏங͍ͯ͠Δ • JavaScript(Ͱ͖ΕTypeScript)͕ॻ͚Δ • σβΠϯγεςϜ / ΨΠυϥΠϯ͕͋ΔνʔϜ
• PWA / Native APP / LIFF(LINE Frontend Framework)ͳͲʹల։ • ՝ۚϝσΟΞͳͲɺas a ServiceԽΛݕ౼͍ͯ͠Δ -
ʮͦͷυϦϧͰͲΜͳ͕݀࡞ΕΔ͔ʯΛߟ͑Δ • ϑϩϯτͷσϓϩΠճ͕ଟ͍ͳΒɺ ViewͱAppΛͨ͠ํ͕ӨڹൣғΛߜΕΔ • App / DB͕མͪͯαΠτ͕མͪͳ͍ͷSSGͷಛ • ʮComponentͷϥΠϒϥϦԽʯͰσβΠϯͷඪ४Խ͕͍͢͠
• WPςʔϚͷΑ͏ʹΫϦοΫͰ؆୯ʹαΠτ࡞Εͳ͍ • ʮ࠶ར༻͍ͨ͠ / Ͱ͖ΔView͕͋Δ͔ʯ͕͓ͦΒ͘ਫྮ -
Thanks you! • Why do I make my blog using
Headless WP with Next.js • How did I made it • Why do we make a website using Headless WP Shifter https://getshifter.io Twitter @motchi0214 GitHub https://github.com/hideokamoto/ -
A P P E N D I X ͜ ͏
͍ ͏ ͜ ͱ Ͱ ͖ Δ • Ionic / CapacitorಋೖͰ Native friendlyʹ • AlgoliaಋೖͰWordPressͷ ΞΫηεΛθϩʹ • Cognito / Auth0 + StripeͰ Paywallͷ࣮ݧͱ͔͍ͨ͠ -
Appendix: Trial resources • Example(SSG): Gatsby WordPress https://github.com/getshifter/example-gatsby-capacitor-wordpress • Example(SSR):
Frontity https://github.com/getshifter/example-frontity-wordpress • Example(SPA): Ionic React with Capacitor https://github.com/getshifter/example-ionic-react-capacitor • Starter theme : Gatsby for WP with TypeScript https://github.com/getshifter/gatsby-starter-wordpress-typescript -
Thanks you! • Why do I make my blog using
Headless WP with Next.js • How did I made it • Why do we make a website using Headless WP Shifter https://getshifter.io Twitter @motchi0214 GitHub https://github.com/hideokamoto/