ããã«ã¡ã¯ãæ ªå¼ä¼ç¤¾ã«ããã·ã®ã¨ã³ã¸ã㢠@tomiã§ãã
ååãããµã¼ãã¹ãµã¤ããGatsbyÃWordpressÃNetlifyã§Jamstackãªãµã¤ãã«ãªãã¥ã¼ã¢ã«ãã¨ããè¨äºãæ¸ããããããã®åé¿ãããã ãã¾ããããããã¨ããããã¾ãã
kaminashi-developer.hatenablog.jp
ä»åã¯ãGatsbyã»Wordpressã»Netlifyã§éçºããã¨ãã®èºãã«ã¤ãã¦ã®è©±ã§ãä¼¼ãæ§æã§éçºãããæ¹ã®å½¹ã«ç«ã¤ã¨æãã¾ãã
éã«ãéãæ§æã®å ´åã¯ãå ¨ãããã«ãªããªãå 容ã¨ãªã£ã¦ãã¾ãã®ã§ãã容赦ãã
éçºãã¦ãã¦èºããã¨ãã
- Dockerä¸ã§WordpressããGraphQLã§ã®è¨äºã®åå¾ãã¨ã©ã¼ã«ãªã
- WordpressãGraphQLã§èªã¿è¾¼ãéãã©ã°ã¤ã³ã®ãã°ããã
- Gutenbergã®ãããã¯ä½æã«æããã£ã
- Gutenbergãããã¯ã®TypeScriptã®åæå®ã«å°ã£ã
- Netlifyã§buildã¨ã©ã¼
- Netlifyã«ãã¼ã ãµã¼ãã¼ãå¤æ´ããã«ã«ã¼ããã¡ã¤ã³ãç¹ãã
åèºãã®è§£æ¶æ¹æ³
â Dockerä¸ã®Wordpressããè¨äºã®åå¾ãã¨ã©ã¼ã«ãªã
Dockerã§éçºç°å¢ãæ´åãã¦ããéã以ä¸ã®ãããªã¨ã©ã¼ãçºçããã
error gatsby-source-wordpress Unable to connect to WPGraphQL. Received HTML as a response. Are you sure http://wordpress/graphql is the correct URL?
Wordpressã¸ã®æ¥ç¶ã¨ã©ã¼ãçºçãã¦ãã¾ã£ãã
åå ã¯ãWordpressã®URLè¨å®ã®ã¢ãã¬ã¹ã«å¼·å¶çã«ãªãã¤ã¬ã¯ãããããã
Wordpressã®ä»æ§ã¨ãã¦ããµã¤ãã¢ãã¬ã¹ã«è¨å®ããã¦ããURLã«ãªãã¤ã¬ã¯ããããã
â 127.0.0.1:8000ã«ã¢ã¯ã»ã¹ããããlocalhost:8000ã«ãªãã¤ã¬ã¯ãããã
ãã®ãããhttp://wordpress/graphqlããåå¾ãããã¨ããããlocalhost:8000ã«ãªãã¤ã¬ã¯ãããã¦ãã¾ãã
Gatsbyã³ã³ããããlocalhost:8000ã«ã¢ã¯ã»ã¹ãã¦ãWordressã³ã³ããã«ã¢ã¯ã»ã¹ãããã¨ã¯ã§ããªãã®ã§ãæ¥ç¶ã¨ã©ã¼ãçºçãã¦ãã¾ã£ãã
解決æ¹æ³
http://wordpress/graphqlã§ã¢ã¯ã»ã¹ã§ããããã«ãdocker-compose.ymlã«ä»¥ä¸ã®è¨å®ã追å ãã¾ããã
wordpres: environment: WORDPRESS_CONFIG_EXTRA: | define('WP_SITEURL', 'http://' . $$_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $$_SERVER['HTTP_HOST']);
ãã®è¨å®ã«ãã£ã¦ãWordpressã«ã¢ã¯ã»ã¹ããéã®URLããµã¤ãã¢ãã¬ã¹ã¨ãªãã
ãã®ããã¯ã¯WordpressãDockerã§èµ·åããéã«ãã使ããããªã®ã§ãè¦ãã¦ããã¨ä¾¿å©ããã
â¡ WordpressãGraphQLã§èªã¿è¾¼ãéãã©ã°ã¤ã³ã®ãã°ããã
gatsby-source-wordpress-experienceã¯ã¾ã ã¾ã ãã°ãããããã§ãã
gatsby-source-wordpressã¨ããã®ãä»ã®ã¡ã¤ã³ãã¼ã¸ã§ã³ã ãããããã°ããããã¨ç ´å£çå¤æ´ãæ¥ãã®ã§ãå¤å°ã®ãªã¹ã¯ã¯æ¿ç¥ã§æ¬¡ã®ãã¼ã¸ã§ã³ã§ããgatsby-source-wordpress-experienceã使ããã¨ãé¸æãã¾ããã
ä»åå¼ã£ããã£ãã®ã¯ãã«ãã´ãªã®å°ã«ãã´ãªãåå¾ã§ããªãã¨ãããã°ãï¼ä»ã¯è§£æ±ºæ¸ã¿ï¼ https://github.com/gatsbyjs/gatsby-source-wordpress-experimental/issues/145
éçºãé²ãã¦ãããã¡ã«ãããï¼ãã¾ãåå¾ã§ããªãã»ã»ã»ã¿ãããªãã¨ãããã
ã¡ãªã¿ã«ãGutenbergãããã¯ã®åå¾ããããã¤ããã¨ãåå¾ã§ããããã¾ã«ãããã¤ã¨ã©ã¼ãçºçããã
çºçæ¡ä»¶ã¯ä¸æã ããWP管çç»é¢ãããWP GraphQL Gutenbergããã©ã°ã¤ã³è¨å®ãã¼ã¸ã®Updateãã¿ã³ãæ¼ãã¦ãããããã¤ããã¨æ²»ããã
⢠Gutenbergã®ãããã¯ä½æã«æããã£ã
Gutenbergãããã¯ãèªä½ãããã¨æã£ã¦ãããªããè¦æãæã£ã¦åãçµã¿ã¾ãããï¼
ã¨ããããããã¥ã¡ã³ããå°ãªãããï¼
å¿
èªãªã®ã¯ãå
¬å¼ã®ãã¥ã¼ããªã¢ã«ã
https://ja.wordpress.org/team/handbook/block-editor/tutorials/create-block/
ããã§Gutenbergãããã¯ãä½ããã©ã°ã¤ã³ãä½æããæµããæ´ããã¨ãã§ãã¾ãã
次ã«ãããã¯ã®è¨å®å¨ãã¯ãã¡ãã®ããã¥ã¡ã³ããä½åº¦ãè¦ã¾ããã https://ja.wordpress.org/team/handbook/block-editor/developers/richtext/
ãã ã
- ãªã¹ãå½¢å¼ã®ãããã¯ãä½ãããã ã¨ãã
- æ稿ã¿ã¤ãã®ãã³ãã¬ã¼ãã«ãããã¯ãé ç½®ãã¦ããããã¨ãã
åºæ¬çãªé¨åã¯ããã¥ã¡ã³ãã«æ²è¼ããã¦ããããå®è£ ããã¦ãããã¹ã¦ã®æ©è½ã®ããã¥ã¡ã³ããè¦å½ãããªãã£ãã
ãªã®ã§ããããããã¨ãå®ç¾ã§ããããªã³ã³ãã¼ãã³ããããã¡ãã®ã¡ãã¥ã¼ã®ä¸è¦§ããæ¢ãã
https://developer.wordpress.org/block-editor/components/
ç®çã®ã³ã³ãã¼ãã³ãã½ããªãã¨æã£ã¦ãããã®ããã¥ã¡ã³ãã«ã¯è©³ç´°ã¯æ¸ããã¦ããªãã®ã§ãã³ã³ãã¼ãã³ãã®ãªãã¸ããªãèªã¿æ¼ãï¼ https://github.com/WordPress/gutenberg/tree/master/packages/components/src
ã²ããããã©ã¤ï¼ã¨ã©ã¼ãç¹°ãè¿ãã¦æè¦ãæ´ãããããã¾ããï¼ çµé¨ããã®ã¿ï¼
⣠Gutenbergãããã¯ã®TypeScriptã®åæå®ã«å°ã£ã
WordpressããGraphQLã§åå¾ãããã¼ã¿ãgatsby-plugin-typegenã§åã¯èªåçæã§ãã¦ã¨ã¦ã便å©ã ããç¹å®ã®ãããã¯ã«ã ãããããããã£ã使ãã¨ãã®åæå®ãè¤éã«ãªã£ã¦ãã¾ã£ãã
以ä¸ã®ç»åã®ããã«blocksã®ä¸ã«å¤æ°ã®ãããã¯ã®åãå«ã¾ãã¦ããã
ã»ããã¼ã®éå¬æ¥æãGutenbergãããã¯ããæ½åºãããã¨ããã¨ãæ¥ä»ã®ããããã£ã¯SeminarGuidelineDateBlockType
ã¨ãããããã¯ã®åã«ããå«ã¾ãã¦ããªãã®ã§ãblocksã®æ°ããä¸ããåãæå®ããªããã°ãªããªãã£ãã
ãã®åå®ç¾©ã®ããã«ãã³ã¼ããè¤éã«ãªã£ã¦ãã¾ã£ãã
â SeminarGuidelineDateBlockType
ãæå®ããããã ãã«æ¸ããã³ã¼ã
⤠Netlifyã§buildã¨ã©ã¼
4:26:04 PM: error There was an error in your GraphQL query: 4:26:04 PM: Unknown type "WpSeminarGuidelinesBlock". Did you mean "WpSeminarFlowBlock", "WpSeminarFieldsEnum", "WpSeminarFilterInput", "WpSeminarConnection", or "WpSeminarGroupConnection"?
ä¸è¨ç»åã®ããã«ãã«ãããã¨ã¨ã©ã¼ãã§ããã¨ãããã¾ããã
ã¨ã©ã¼å 容ããå¯ããã«ãèªä½ãããã¯ãGraphQLã§è¦ã¤ããããªãããã§ã
ã³ã¼ãã¯ä»¥ä¸ã®ããã«ãblocksããèªä½ãããã¯ãåå¾ãã¦ããã¨ãããåå ã§ããã
export const wpSeminarEdgeFields = graphql` fragment WpSeminarEdgeFields on WpSeminarEdge { node { blocks { name ... on WpSeminarGuidelinesBlock { innerBlocks { name ... on WpSeminarGuidelineBlock { attributes { content label } innerBlocks { name saveContent ... on WpSeminarGuidelineDateBlock { attributes { endAt startAt } } } } } } } featuredImage { node { localFile { childImageSharp { fixed(width: 1200, height: 628, cropFocus: CENTER) { ...GatsbyImageSharpFixed } } } } } id slug title } } `
解決æ¹æ³
gatsby-node.js
ã§çæãããã¼ã¸ãå
¬éè¨äºã ãã«çµãè¾¼ããã¨ã§ã解決ã§ãã¾ããã
const createSeminar = async () => { // ... const result = await graphql(`{ seminar: allWpSeminar(filter: { status: { eq: "publish" } }) { // <--ãã pageInfo { totalCount } edges { node { slug } } } }`) // ... seminars.forEach((edge, i) => { createPage({ path: `/seminar/${decodeURIComponent(edge.node.slug)}/`, component: showTemplate, context: { slug: edge.node.slug, }, }) }) }
⥠Netlifyã«ãã¼ã ãµã¼ãã¼ãå¤æ´ããã«ã«ã¼ããã¡ã¤ã³ãç¹ãã
Netlifyã«ã«ã¹ã¿ã ãã¡ã¤ã³ãè¨å®ããæ¹æ³ã¯ãNetlify DNSãå©ç¨ããããå¤é¨DNSã®è¨å®ãç·¨éãããï¼ãã¿ã¼ã³ãããã¾ãã
ä»åã¯ãå¤é¨DNSã§ãã¤ã«ã¼ããã¡ã¤ã³ï¼kaminashi.jpï¼ãNetlifyã«ç¹ãã¾ããã
ããã¥ã¡ã³ããè¦ãã¨ãCNAME, ANAME, ALIASã§ç¹ããæ¹æ³ãè¼ã£ã¦ããã®ã§ããã使ã£ã¦ãDNSãµã¼ãã¼ãã«ã¼ããã¡ã¤ã³ã«å¯¾ãã¦CNAMEçã使ããã«å°ããããã¾ããã
çµå±ããã¥ã¡ã³ãã«ç®ããã£ããéãã¦ããããAã¬ã³ã¼ãã§ã®è¨å®ã«ã¤ãã¦ãæ¸ãã¦ããã®ãè¦è½ã¨ãã¦ããã ãã§ããããã
Point the record to Netlify's load balancer IP address:
104.198.14.52
.
ã¾ã¨ã
以ä¸ãGatsbyã»Wordpressã»Netlifyã§éçºããã¨ãã«å®éã«èºããã¨ãããå°ã£ãã¨ããã§ããã
gatsby-source-wordpress-experimental
ãwp-graphql
ãGutenberg
ãã¾ã æçãã¦ããªãã®ã§ãä¸å®å®ãªã¨ãããå¤ãã§ãã
ããããSSGã®Gatsbyãæ¯è¼çæ°ããAPIä¼ç»ã®GraphQLãWordpressã®æ°ããã¨ãã£ã¿Gutenbergã¨æ°ãããã¨ã ããã§ãã£ã¬ã³ã¸ãããã®ããã®æè¡ã§ããã
æ¯ãè¿ã£ã¦ã¿ãã¨ããã®æ稿ã®åæ¥ã«å
¬éããããã«ããã·ãæ²ãã¦ãã3ã¤ã®ããªã¥ã¼ã®ã²ã¨ã¤ã§ãããβçãã¤ã³ãããå®è¡ãã¦ãããªã¨ã
ä»å¾ããã©ã¤ï¼ã¨ã©ã¼ãç¹°ãè¿ããªããæç´ã«æé·ãã¦ããã¾ãã
ã«ããã·ã®ããã·ã§ã³ã»ããªã¥ã¼ãæ°ã«ãªã£ãæ¹ã¯ãã¡ã