IT |
ITmedia 総合記事一覧 |
[ITmedia PC USER] CHUWI、ミニデスクトップPC「CoreBox」に第12世代Core i5搭載の新モデル |
https://www.itmedia.co.jp/pcuser/articles/2304/04/news113.html
|
chuwiinnovation |
2023-04-04 13:33:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia PC USER] MSI、Core i7搭載15.6型ゲーミングノート「Katana GF66」にJoshin web専売モデル |
https://www.itmedia.co.jp/pcuser/articles/2304/04/news112.html
|
corei |
2023-04-04 13:28:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia News] ポケモンGO、前代未聞の課金アイテム使用制限で炎上 狙いをNianticに聞く |
https://www.itmedia.co.jp/news/articles/2304/04/news111.html
|
itmedia |
2023-04-04 13:28:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia ビジネスオンライン] 中間管理職は“ハラハラ” 職場でのハラスメントに神経を使う |
https://www.itmedia.co.jp/business/articles/2304/04/news105.html
|
itmedia |
2023-04-04 13:21:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia ビジネスオンライン] 「甘すぎる」「カロリーが高い」を解決 「アクエリアス NEWATER」発売 |
https://www.itmedia.co.jp/business/articles/2304/04/news107.html
|
itmedia |
2023-04-04 13:12:00 |
TECH |
Techable(テッカブル) |
ジェスチャーで鏡の中の友達と交流。環境音をグラフィック表示…TREEのコンテンツがユニーク |
https://techable.jp/archives/201928
|
treedigitalstudio |
2023-04-04 04:00:44 |
AWS |
AWS Japan Blog |
AWS Summit Tokyo は見どころがいっぱい!製造業向け展示・セッションのご紹介 |
https://aws.amazon.com/jp/blogs/news/aws-summit-tokyo-2023-manufacturing-session/
|
AWSSummitTokyoは見どころがいっぱい製造業向け展示・セッションのご紹介AWSSummitは、クラウドコンピューティングコミュニティが一堂に会して、AmazonWebServicesAWSに関して学習し、ベストプラクティスの共有や情報交換ができる、AWSに興味がある全ての皆様のための無料のイベントです。 |
2023-04-04 04:36:46 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
タスクマネージャーのパフォーマンスをDiscordBotが定期的に教えてくれるPythonのプログラム |
https://qiita.com/Nikto/items/705e682ea8ef81a77451
|
timeclientdiscordclient |
2023-04-04 13:17:50 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
axiosでx-www-form-urlencoded形式のデータをpostする |
https://qiita.com/kzkapr1129/items/ef2475cf0966b97a7843
|
ttypeapplicationxwwwform |
2023-04-04 13:17:22 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
TypeScript, React について +α |
https://qiita.com/OkomeChike/items/8276af3a14b214d946c5
|
typescript |
2023-04-04 13:02:20 |
Linux |
Ubuntuタグが付けられた新着投稿 - Qiita |
UbuntuでBluetoothの設定をクリックしても反応がない |
https://qiita.com/Sicut_study/items/e18c62f58816d6d6e4e9
|
bluetooth |
2023-04-04 13:02:35 |
golang |
Goタグが付けられた新着投稿 - Qiita |
Go 副作用を期待して関数にSliceを渡す際の注意点 |
https://qiita.com/koooyooo/items/6b9062767fb8a31dfafa
|
slice |
2023-04-04 13:00:56 |
Git |
Gitタグが付けられた新着投稿 - Qiita |
Gitの基本的なコマンド |
https://qiita.com/tomohisakk/items/8ef7829832ec4d73ec3b
|
gitclone |
2023-04-04 13:34:05 |
技術ブログ |
Developers.IO |
ChatGPTで構造化面接の設問と評価基準の素案を作成する |
https://dev.classmethod.jp/articles/structured-interview-by-chatgpt/
|
chatgpt |
2023-04-04 04:16:40 |
海外TECH |
DEV Community |
A Detailed Guide on How to Build a Website with Next.js and Headless WordPress + SEO - 2023 Web Development |
https://dev.to/jeffsalive/a-detailed-guide-on-how-to-build-a-website-with-nextjs-and-headless-wordpress-seo-2023-web-development-4nof
|
A Detailed Guide on How to Build a Website with Next js and Headless WordPress SEO Web DevelopmentIf you haven t heard about Next js and WordPress don t worry you can check out the links I ve included to learn more about them Next jsWordPressIn this article we ll together be exploring the power of combining Headless WordPress and Next js two technologies that have become increasingly popular in recent years By using these together we can create a website that is not only incredibly fast but also SEO friendly and provides an exceptional user experience This guide is perfect for both experienced developers and those who are just starting out as I ll be providing all the necessary knowledge and tools to help you create cutting edge websites in Throughout this post I ll be working on building a simple blog using Next js and Headless WordPress You can check out the finished product at the link provided and the code can be found in the GitHub repository Finished ProductGitHub RepoWhile WordPress is a well known content management system not everyone is familiar with Headless WordPress I ll be covering what it is and why it s important What is Headless WordPress In traditional WordPress setups the content management system CMS and frontend are closely tied together tightly coupled Essentially WordPress handles both the content management and presentation aspects of user interactions However with Headless WordPress we ve got a new way of using the platform that separates the CMS from the frontend presentation layers This approach allows us developers to use the CMS as a content repository similar to a backend and use the provided API to fetch content as needed on the frontend The best part is that we re no longer limited to using WordPress for the frontend but can choose any technology we prefer like React Vue js Angular or in our case Next js What about the benefits Well they are pretty amazing As developers this technology gives us the power to build applications with greater flexibility improved performance and better separation of concerns between the CMS and frontend We can build custom high performance front ends while still leveraging the powerful content management capabilities of WordPress In this setup here are some of the things we will cover Next js setup with TypeScript WordPress setup on Local by Flywheel which will enable us establish a server for WordPress installation WordPress installation You may also utilize XAMPP WAMP or any other familiar tool Downloading and configuring plugins Connecting our WordPress and building our blog Deploying our blog Optimizing blog for SEO A live url is necessary Are you game Let s begin Next js setup with TypeScriptOption Recommended If you want to join me or already know about this you can grab the starter template I made on GitHub It s got useful stuff like React components and project styling Just run npm install or yarn install to install the dependencies Here s the link to the starter template Grab it here Option But if you prefer to go the extra mile and set up Next js with TypeScript on your own keep reading To begin create a new folder for this project on your desktop or any location you prefer I called mine the headless blog The fastest way to start a Next js project with TypeScript is to use the npx create next app command with the typescript flag Open your project folder in your favorite IDE and run this command on the terminal npx create next app latest typescript You ll be prompted to answer some questions about your project confiuration To follow along here are the options I chose What is your project named specifying to use my folder name as the project name You can enter a name of your choice Would you like to use ESLint with this project YesWould you like to use src directory with this project NoWould you like to use experimental app directory with this project NoWhat import alias would you like configured Let s keep it moving WordPress Installation and Setup on LocalFeel free to skip this part Local by Flywheel is an effortless way to develop WordPress sites locally It s quite similar to tools like XAMPP and WAMP but it s my go to for setting up WordPress locally You can learn more and download here and it s free To begin creating a new site open Local by Flywheel navigate to the green plus icon located at the bottom left of the window Clicking on it will prompt you to select an option for creating a new site Choose the Create a new site option and click on continue After this you will be taken to a new screen where you can enter a name for your site Simply type in any name you prefer and click on the continue button You will then be given the option to select an environment Generally the preferred option should suffice but if you wish to customize your environment select the Custom option The next step is to enter your WordPress credentials which include a username password and email address Once you have entered these click on the Add site button Allow some time for the site to deploy and once the process is complete click on the Start site button if it hasn t already started To access the WordPress dashboard click on the WP Admin button and log in using the credentials you created earlier Congratulations Your WordPress installation is now complete Downloading and Configuring PluginsRecall that our plan is to use WordPress as a content respository only and then fetch content through APIs By default WordPress offers a basic REST API for retrieving and managing content and data However in this project we will use the WPGraphQL plugin to enhance performance and align with personal preferences WPGraphQL This is an open source and free WordPress plugin that offers a user friendly GraphQL API for your WordPress website Rather than utilizing the standard WordPress REST API we ll be using GraphQL a query language for APIs that Facebook developed It allows you to request only the data you require from an API increasing the speed and efficiency of your applications With the help of the plugin we will be able to retrieve data from WordPress using GraphQL queries Click here to learn more about the GraphQL query language To install navigate to the plugins directory on your WordPress dashboard and search for graphql Proceed to install and activate the WPGraphQL plugin As of the time of writing it boasts over active installations Let s pause a minute to generate at least three to five dummy posts in WordPress Each post should include a title a featured image and an excerpt We will retrieve these posts on our frontend at a later stage Connecting our WordPress and building our blogIn the Next js setup section I added a link to grab the starter template here The starter template includes useful code for the React components and styling that I ll be using and I ve also integrated TailwindCSS to reduce the amount of CSS code you need to write I ll be mostly focused on getting our project connected to WordPress pulling posts from there and displaying them on the screen After that I ll dive into the SEO stuff To link WordPress to our project go to your WordPress dashboard If you ve installed and activated the WPGraphQL plugin it should now show up on the dashboard with a label that says GraphQL Click on it and go to the GraphQL settings page On the WPGraphQL General Settings page in the settings you ll find the GraphQL Endpoint we need to connect WordPress to our project This endpoint allows us to communicate with WordPress from the frontend and fetch content as required Simply copy the endpoint which should look like a URL beginning with either http or https Back in our project folder create a env file in the main directory It s a file used to store environment variables such as API keys database credentials or the endpoint we just copied Once the file is created add a key for the endpoint and save the file You can name it NEXT PUBLIC WORDPRESS API ENDPOINT Whatever you name it be sure it starts with NEXT PUBLIC Next let s create a new folder in the main directory and name it lib Inside this folder create two new files base ts and service ts Copy and paste the following code into the base ts fileconst API URL lt string gt process env NEXT PUBLIC WORDPRESS API ENDPOINT export async function fetchAPI query variables Record lt string any gt const headers Content Type application json const res await fetch API URL headers method POST body JSON stringify query variables const json await res json if json errors console error json errors throw new Error Failed to fetch API return json data In the base ts file we are exporting the fetchAPI function which is used to fetch data from the WordPress endpoint we stored in the env file We can pass a query string and a variables object to it to make a request to the endpoint and retrieve the desired data Now let s proceed to write the query to fetch all blog posts from WordPress In your WordPress dashboard navigate to the GraphQL IDE The IDE allows us to experiment with GraphQL queries and see the structure of the data that is returned This can help you understand how to structure your queries and align the data with the needs of your application Click on the Query Composer button to open the composer With the composer you can create GraphQL queries by toggling the relevant data types and their available options To learn more about making queries in WPGraphQL you can refer to this resource Since we want to fetch posts here s the query to fetch the first a number of blog posts from WordPress query FetchPosts first Int posts first first nodes excerpt featuredImage node sourceUrl slug title The variable first is the number of posts to fetch per request The default number is When you run the query this the structure of the response Moving along back in your project folder copy and paste this code in your service ts file import fetchAPI from base export async function getPosts first const data await fetchAPI query FetchPosts first Int posts first first nodes excerpt featuredImage node sourceUrl slug title variables first return data posts nodes See how we passed the FetchPosts query to the fetchAPI function When the getPosts function is called it makes a request and fetches the specified number of posts returning the data The service ts file provides a space for defining additional functions services to retrieve and manage data in WordPress We ll retrieve and display the posts on the home page which is the index tsx file inside the pages folder For static site generation we will use the getStaticProps and getStaticPaths functions to pre render the page To learn more about data fetching and pre rendering in Next js refer to this resource In the index tsx file we need to import the GetStaticProps type from the next module because we re using TypeScript We also have to import the getPosts service from the lib directory import GetStaticProps from next import getPosts from lib service After that we need to create a function called getStaticProps just below the HomePage function Inside this function we ll call the getPosts service to request data from WordPress Once we have the posts we ll return them as a prop which will be passed to the HomePage function default export export const getStaticProps GetStaticProps async gt const posts await getPosts retrieve first posts return props posts revalidate When the getStaticProps function is called it will return an array of posts which will be passed to the HomePage function as a prop We can access this prop inside HomePage Each post in the returned array is an object with properties like title slug excerpt and featuredImage as we can see by examining the structure of each post in the WPGraphQL IDE To display each post on the HomePage we ll need to map through the array of posts and create a PostBlock component for each one The PostBlock component is located in the components folder We ll also need to modify the PostBlock component to work with the title slug excerpt and featuredImage properties of each post and display the data appropriately Here s the updated index tsx file import GetStaticProps from next import Hero from components Hero import PostBlock from components PostBlock import getPosts from lib service export default function HomePage posts posts any return lt gt lt Hero gt lt div className container mx auto py gt lt h className text xl gt All my posts lt h gt lt div className my grid grid flow row grid cols md grid cols lg grid cols gt posts map post any gt return lt PostBlock key post slug post post gt lt div gt lt div gt lt gt export const getStaticProps GetStaticProps async gt const posts await getPosts retrieve first posts return props posts revalidate To make sure that the PostBlock component can display the data for each post correctly we need to modify it You can find the PostBlock component inside the components folder We ll need to make sure that the PostBlock component can access the title excerpt slug and featuredImage properties of each post that we re passing in Then we can use these properties to display the data appropriately For example we might want to display the post s title as a heading the excerpt as a short summary and the featured image as a thumbnail We ll also need to create a link that takes the user to the full post when they click on it import Link from next link import Image from next image import defaultImage from assets images default jpg export const PostBlock post post any gt return lt div className post block p rounded md gt lt Link href blog post slug gt lt div className relative h transition all duration ease linear hover translate y px gt lt Image src post featuredImage node sourceUrl defaultImage fill alt post title className absolute rounded md h full w full object cover gt lt div gt lt Link gt lt Link href blog post slug className post content my gt lt h className text xl py gt post title lt h gt lt p className italic gt post excerpt lt p gt lt Link gt lt div gt Make sure to test the PostBlock component after making the modifications to ensure that the data is being displayed correctly Once you ve made all the necessary changes to your code you can start your development server by running the npm run dev command in your terminal Make sure that your local server for WordPress is still running Next js will typically start the server on port so navigate to http localhost in your browser to view the site If everything is working correctly you should see the homepage of your site but with an error on the screen like so This error is related to the usage of the next image component in Next js The error message indicates that the src property of the next image component is pointing to an image file with a URL that includes a hostname the headless blog local which is not allowed by the next image configuration If you want to use images from a source other than your Next js project you ll need to configure your next config js file properly This includes creating a list of allowed domains from which images can be loaded This security measure is in place to prevent cross site scripting XSS attacks So to fix the error you re seeing you can add the the headless blog local hostname to the list of allowed domains in your next config js file This should allow you to load images from your WordPress server Learn more here After making changes to your code you will need to restart your development server in order to see the changes take effect To do this stop the current instance of your development server by pressing Ctrl C in your terminal Then run the npm run dev command again to start the development server with your updated code This should ensure that your changes have been properly propagated and are visible in your browser Congratulations on successfully retrieving posts from your WordPress server However there is one more modification we need to make to the PostBlock component The excerpt returned from WordPress is an HTML paragraph so we need to make some adjustments to ensure that it is displayed properly To do this we can change the p tag in the PostBlock component to a div tag and use the dangerouslySetInnerHTML attribute to display the excerpt as HTML This will ensure that the excerpt is displayed properly and any HTML tags in the excerpt are rendered correctly Here s the updated code for the PostBlock component import Link from next link import Image from next image import defaultImage from assets images default jpg export const PostBlock post post any gt return lt div className post block p rounded md gt lt Link href blog post slug gt lt div className relative h transition all duration ease linear hover translate y px gt lt Image src post featuredImage node sourceUrl defaultImage fill alt post title className absolute rounded md h full w full object cover gt lt div gt lt Link gt lt Link href blog post slug className post content my gt lt h className text xl py gt post title lt h gt lt div className italic dangerouslySetInnerHTML html post excerpt gt lt div gt lt Link gt lt div gt After saving the changes our posts should be rendered correctly To display the correct number of posts on the homepage we need to modify the HomePage function to access the length property of the posts array Currently clicking on any post on the homepage will take you to the page To fix this we need to establish a dynamic route for the post details page To do this we can create a new folder called posts inside the pages folder Inside the posts folder we can create a new file called slug tsx This will be the template used to render the details of each post After creating the slug tsx file we can update the link structure in the PostBlock component from blog post slug to posts post slug to match the new dynamic route we just created This will ensure that clicking on a post on the homepage takes you to the correct post details page Next to fetch a single post by slug we can create and export a new service in the service ts file inside the lib folder Here s the query we can use to fetch a single post by slug query GetPost id ID post id id idType SLUG content featuredImage node sourceUrl slug title And here s the service to get a single post by slug export async function getPostBySlug slug string const data await fetchAPI query GetPost id ID post id id idType SLUG content featuredImage node sourceUrl slug title variables id slug return data post We ll call the getPostBySlug function inside the getStaticProps function in the slug tsx file This function will return the post data which we ll then pass as a prop to the page component for rendering You can copy and paste the code provided below into the slug tsx file and find the code explanation right after it import GetStaticProps from next import GetStaticPaths from next import getPosts getPostBySlug from lib service export default function PostDetails post post any return lt section className container mx auto py gt lt div className post header relative flex flex col items center justify center w full min h px rounded md style backgroundImage url post featuredImage node sourceUrl backgroundSize cover backgroundPosition center gt lt div className absolute w full h full z style backgroundColor rgba gt lt div gt lt div className z text center gt lt h className text xl md text xl mb gt post title lt h gt lt p className italic gt By Jeffrey lt p gt lt div gt lt div gt lt div className post content w full md w mx auto mt py text lg dangerouslySetInnerHTML html post content gt lt div gt lt section gt export const getStaticPaths GetStaticPaths async gt const posts await getPosts retrieve first posts return paths posts map post any gt posts post slug fallback false export const getStaticProps GetStaticProps async params gt const post await getPostBySlug params slug as string return props post The PostDetails function is the component that will render the post page It receives a post object as a prop which contains the information about the post to be rendered The function simply renders a header section for the post which includes the post s featured image title and author We also render the post s content right below it In Next js if a page has dynamic routes and uses getStaticProps it needs to define a list of paths to be statically generated Next js will generate the necessary pages for each route each post at build time This means that when a user visits one of our posts they will see a pre rendered version of the page rather than waiting for the page to load and render on the client In this specific case it retrieves the first posts using the getPosts function from our service ts file and maps over them to create an array of paths that corresponds to the slug of each post The fallback property is set to false which means that if a user navigates to a post that doesn t exist Next js will return a page The getStaticProps function has been used before in the index tsx file but in this case note that the slug parameter is obtained by destructuring the params object passed to the function We use slug because it corresponds to the name of our file which is slug tsx and is enclosed in square brackets You can learn more about Next js routing here After saving all the changes clicking on a post in the home page should take you to the corresponding post details page in your browser Deploying our BlogIt s time to share our work with the world To make a website or blog using the WordPress Next js combination go live we need to first set up an online server for the WordPress backend and then deploy the Next js frontend on Vercel or on any other static hosting providers Important Usually you would get a domain name like example com and point it to your Frontend deployed on Vercel Then you can create a subdomain such as api example com for the WordPress backend This allows you to use your primary domain name for your website while the subdomain serves as a server for your site s backend But in our case we won t be creating a domain name or subdomain for our project Instead we ll use a free hosting service called webhost to host our WordPress backend and then deploy our Frontend on Vercel Deploying our WordPress backend Go to and create a new account Don t forget to verify your email address and the best part it s free Login and navigate to Click on the Create New Site button and enter a website name and password in the modal form Finally click on the Create button and you ll be redirected to the dashboard when the process is completed The next step is to install WordPress From the dashboard click on the WordPress card and then fill out the form on the screen by entering your desired admin username and password Once you ve filled out the form click on the Install button and wait for the WordPress installation process to complete After installation click on the Go to configuration page button and you ll be prompted to log in Enter the admin username and password you created in the previous step If you encounter a page or are redirected to the website lists page try step again On the WordPress dashboard we need to download and configure plugins as well as create some posts just like we did earlier in this article However if you want to migrate your local WordPress installation to your live one you can easily use a plugin called All in one WP Migration You can learn more about migration with the plugin here Since we don t have much content on our local WordPress installation we can simply repeat the process Deploying our Frontend on VercelBefore proceeding ensure that you have created a GitHub account and that you have knowledge of Git If you don t have knowledge of Git you can click here to learn more Next open the next config js file in your working folder and add the new domain of your live WordPress hostname in the domains array api headless blog webhostapp comCreate a new repository for your frontend on your GitHub account You can name it nextjs headless wordpress In your working folder run the following commands one after the other in your terminal to initialize Git and push your code git initgit commit m first commit git branch M maingit remote add origin lt your git repo url gt git push u origin mainAfter pushing your code to the main branch go to and log in using your GitHub account On the dashboard add a new project and click on the Import button next to the repository you just created On the project configuration page in the Environment Variables section enter the WordPress API endpoint as you did locally but use the live WordPress GraphQL endpoint instead Then click on the Add button NEXT PUBLIC WORDPRESS API ENDPOINT lt live endpoint gt Click on the Deploy button to start the deployment process If everything went smoothly your project should now be deployed without any hiccups If you run into any issues double check your steps and try again Now here s the exciting part you can share your newly created blog with your friends Here s the link to mine Optimizing Blog for SEOIf this article has been helpful so far give me a follow on Twitter In a Twitter s Space a developer expressed concerns about Next js and React not being a suitable choice to build a blog due to the difficulty in optimizing for SEO However in optimizing for SEO on your website or blog is quite achievable In this section we ll cover the following Creating a custom SEO componentGenerating sitemapGoogle site ownership verification Creating a Custom SEO ComponentWe will implement a custom SEO component that can enhance the search engine optimization SEO of our blog by generating meta tags and other HTML markup This component will accept multiple props including the page s title description image and type to create relevant meta tags for both search engine indexing and social media sharing Additionally it will incorporate links to different icons like the favicon and set the canonical URL to avoid duplication issues The utilization of this component will ensure that our blog has optimized meta tags resulting in improved search engine rankings and an enhanced user experience when sharing the site on social media platforms Step Add a new environment variable called NEXT PUBLIC ROOT URL in the env file with the value set to the root URL of our blog As we are currently in the development phase the root URL should be http localhost Step Create favicons for your blog using an online generator like Favicon io These icons will be utilized in the upcoming SEO component It is recommended to generate types of icons for optimal optimization including faviconIco This is the favicon icon for the blog website which appears in the browser tab and bookmarks favicon This icon is used for Apple devices when a user adds a website to their home screen favicon This is another favicon icon but with a size of x pixels favicon This favicon icon is even smaller with a size of x pixels maskIcon This is a special icon that is used as the mask for the pinned tab icon in Safari browser However I won t be generating a maskIcon for this project After generating the favicons using the online generator a zip file containing the icons will be downloaded Alternatively you can create these icons yourself in any way that you prefer In the assets folder create a new folder for the icons You can name it favicons and copy the downloaded icons inside the folder In the components folder create a new folder and name it SEO Inside the folder create an index tsx file which will hold the code for the component Copy and paste the code below into your file import Head from next head import useRouter from next router import faviconIco from assets favicons favicon ico import appleTouchIcon from assets favicons apple touch icon png import favicon from assets favicons favicon x png import favicon from assets favicons favicon x png import defaultImage from assets images default jpg interface SEOProps title string description string image string type website article const pageImage process env NEXT PUBLIC ROOT URL defaultImage src slice const ROOT URL process env NEXT PUBLIC ROOT URL as string export const SEO title description image pageImage type website SEOProps gt const router useRouter const url ROOT URL router asPath return lt Head gt lt title gt title lt title gt lt meta charSet utf gt lt meta name viewport content width device width initial scale gt lt meta content IE edge httpEquiv X UA Compatible gt lt meta name description content description gt lt meta name robots content follow index gt lt meta name twitter card content summary large image gt lt meta name twitter site content JeffreySunny gt lt meta name twitter image content image gt lt meta name twitter title content title gt lt meta name twitter description content description gt lt meta property og site name content Jeffrey s Blog gt lt meta property og title content title gt lt meta property og description content description gt lt meta property og url content url gt lt meta property og type content type gt lt meta property og image content image gt lt link rel shortcut icon href faviconIco src gt lt link rel apple touch icon sizes x href appleTouchIcon src gt lt link rel icon type image png sizes x href favicon src gt lt link rel icon type image png sizes x href favicon src gt lt link rel mask icon href color bbad gt Add mask icon lt meta name msapplication TileColor content dac gt lt meta name theme color content ffffff gt lt link rel canonical href url gt lt Head gt The components generates meta tags and other HTML markup to improve search engine optimization SEO for our blog It takes four props title description image and type to generate appropriate meta tags for social media sharing and search engine indexing I included various meta tags including those for Twitter and Open Graph as well as link tags for the different sizes of favicons The canonical link is also set to ensure that search engines index the correct URL and to avoid duplicates Let s modify our pages index tsx and posts slug tsx files to use the new SEO component pages index tsxexport default function HomePage posts posts any return lt gt lt SEO title Welcome to Jeffrey s Blog description Access all tech content and beyond gt lt Hero gt lt div className container mx auto py gt lt h className text xl gt All my posts posts length lt h gt lt div className my grid grid flow row grid cols md grid cols lg grid cols gt posts map post any gt return lt PostBlock key post slug post post gt lt div gt lt div gt lt gt And here s the result posts slug tsxexport default function PostDetails post post any return lt gt lt SEO title post title Posts description post excerpt image post featuredImage node sourceUrl type article gt lt section className container mx auto py gt lt div className post header relative flex flex col items center justify center w full min h px rounded md style backgroundImage url post featuredImage node sourceUrl backgroundSize cover backgroundPosition center gt lt div className absolute w full h full z style backgroundColor rgba gt lt div gt lt div className z text center gt lt h className text xl md text xl mb gt post title lt h gt lt p className italic gt By Jeffrey lt p gt lt div gt lt div gt lt div className post content w full md w mx auto mt py text lg dangerouslySetInnerHTML html post content gt lt div gt lt section gt lt gt On the post details page the post s title excerpt and featured image are passed to the SEO component The page s type is set to article to indicate the type of content it represents If you inspect the head element using developer tools you will see all the SEO tags that we included which are necessary for optimizing the page s search engine ranking Generating SitemapWhy are we generating a sitemap Sitemaps help search engines like Google to crawl and index a website more effectively making it easier for users to discover the content on the site and they can be submitted to search engines as part of the website s search engine optimization SEO strategy To generate a sitemap for our blog To install the sitemap generator package for Next js run npm install next sitemap Then create a basic config file named next sitemap config js in your root directory and add the following code into it type import next sitemap IConfig module exports siteUrl process env NEXT PUBLIC ROOT URL generateRobotsTxt true Ensure you use the correct environment variable that points to your root url Make sure to use the right root url environment variable if yours is different Then add a postbuild script with the value next sitemap in package json This script will generate a sitemap for our blog right after the build script is run Run the npm run build command on your terminal and after which start your development server A sitemap for your blog should have been generated and you can access it on this link http localhost sitemap xml Google Site Ownership VerificationA key part of search engine optimization SEO is verifying ownership of your domain website and there are several benefits of verfying your domain or website or in this case our blog with Google including Indexing of your website Google uses your site ownership verification as a way to confirm that you are the owner of a website which can help to ensure that your website is properly indexed in Google search results Security It helps to prevent unauthorized access to your website and to ensure that you have control over your website s presence on Google search SEO By accessing Google Search Console you can monitor your website s or blog s performance on Google search results and identify opportunities to improve your search engine optimization SEO efforts To verify ownership of your blog on Google follow these steps Sign into your Google account and access Google Search Console Click Add property and enter your blog s homepage URL which should be the live link of your blog e g Select the appropriate property type when prompted If you have a custom domain choose the Domain tab and enter your domain name Otherwise choose the URL prefix tab and click Continue Select the HTML tag verification method and copy the provided meta tag Do not close the modal or click anything Open the SEO component file in the components folder and paste the meta tag code within the Head tag like this Important You need to add the NEXT PUBLIC ROOT URL environment variable to the project settings of your project on Vercel This variable should be set to the live URL of your blog such as Don t forget to hit the Save button Pushing our updated code to GitHub allows us to redeploy our blog The following commands should be executed sequentially git add git commit m sitemap generation and adjustment git push origin mainOur Vercel setup is configured to monitor changes made on the main branch and will automatically redeploy the blog once an update is detected After successfully deploying go back to the Google Search Console page and click on the Verify button If the meta tag has been added correctly a message reading Ownership verified should appear on the screen In addition you need to add the sitemap to Google Search Console On the sidebar click on the Sitemaps link In the Add a new sitemap box enter sitemap xml which is the location of our sitemap and click Submit Congratulations Your blog is now SEO optimized and ready to be crawled by search engines though it may take some time for the sitemap to fully propagate SummaryThank you for staying with me until this point folks I want to emphasize that this comprehensive guide is not limited to just blogs It can also be used to develop robust web applications such as e commerce sites real estate listings online directories and more By utilizing plugins such as Advanced Custom Fields and WooCommerce you can create custom fields and layouts tailored to your application s needs With authentication and authorization features WordPress can serve as your backend while Next js handles your frontend resulting in a highly responsive and cost effective website Thank you for staying with me If you found this guide helpful please consider following me on Twitter Feel free to leave your comments thoughts and questions in the comments section below I would be delighted to respond to them Image sources |
2023-04-04 04:39:20 |
海外TECH |
DEV Community |
Conditional Statements in JavaScript: Switch |
https://dev.to/max24816/conditional-statements-in-javascript-switch-53l
|
Conditional Statements in JavaScript SwitchIn JavaScript the switch statement is another way to achieve the conditional statements instead of if else While doing multi level condition check this one is really helpful The Switch StatementThe switch statement evaluates an expression and compares it with a series of cases If there is a match the code inside that case is executed The switch statement is often used as an alternative to the if else statement when multiple conditions need to be evaluated break keyword is used in each case to break the switch statement once the case condition is true if break is not used then it will check other case condition statements default keyword is used at the end of switch this block will be executed if the above case are not true syntax switch expression case value code to be executed when expression matches value break case value code to be executed when expression matches value break default code to be executed when none of the cases match expression Here expression is the expression to be evaluated and value value etc are the cases to compare with the expression If the expression matches value the code inside that case will be executed The break keyword is used to exit the switch statement If none of the cases match the expression the code inside the default case will be executed Example let number switch dayOfWeek case console log ONE break case console log TWO break case console log THREE break case console log FOUR break case console log FIVE break default console log Invalid Number In this example since number is the message TWO will be printed to the console |
2023-04-04 04:34:02 |
海外TECH |
DEV Community |
Using the Linux Free Command With Examples |
https://dev.to/danielfavour/using-the-linux-free-command-with-examples-4lkc
|
Using the Linux Free Command With ExamplesI wrote this article originally for TuringRegular memory checks are crucial to maintaining the performance of your Linux system Knowing your system s memory can also aid in debugging and preventing poor application response times while running memory intensive programs There are several ways to view the RAM on your Linux system using the command line but for the scope of this article we will focus on the free command In this article we will discuss what the Linux free command is how it works and the benefits of the command What is the free command The free command is a Linux command that allows you to check for memory RAM on your system or to check the memory statics of the Linux operating system To view your system s memory statics run the free command in your terminal as shown below user ubuntu free total used free shared buff cache availableMem Swap Understanding the outputThe output of the free command provides various metrics related to system memory including total used free shared buff cache and available To gain a comprehensive understanding of these fields it is important to examine each one individually To begin we ll focus on the Mem metric which represents the total amount of physical RAM installed on the system Examining the Mem metrics and its fieldsThe Mem metric as displayed in the output of the free command serves as a measurement of the physical RAM Random Access Memory installed on a computer system It offers a comprehensive view of the total amount of installed RAM and its current usage by running programs and processes By monitoring this metric it is possible to detect any potential memory related issues within the system The Mem metric also includes several fields that give an overview of the system s memory usage such as Total This is the total amount of physical RAM on your system Used This shows the amount of memory that has been used up or amount of RAM that is currently being utilized by running programs and processes Free This is the amount of physical memory that is not currently being used by any running processes and is ready to be allocated to new processes Shared This displays the total amount of memory used by the temporary tmpfs file system Tmpfs is a file system that stores files in the computer s main memory RAM making it faster to access compared to traditional storage methods like a hard drive Buff cache This is the memory that the kernel operating system uses to store recently used data so that it can be accessed quickly It is used to speed up the performance of the computer by reducing the amount of time it takes to access data from the hard drive Think of it like a temporary storage area where the computer stores data that it might need soon so that it doesn t have to search for it again later Available This shows an estimated value of how many memory resources are still open for use This value can fluctuate as processes start and stop and memory is freed up and allocated So while it may not actively be used by a process at the moment it is still available to be allocated to a process if needed Free and available memory can be tricky to understand Think of free memory as empty rooms in your house that are ready to be occupied representing the amount of physical memory that is not currently being used by any running processes and is ready to be allocated to new processes You can also think of available memory as the total number of rooms that can be occupied including the empty ones and the ones in use for caching and buffering An example of caching would be storing items in a storage room that you frequently use so that you can easily access them when you need them Buffering would be like having a guest room ready to be used in case you have unexpected visitors Both the storage room and guest room are being used but they are still considered available because they can be used for their intended purpose if necessary Examining the swap metrics and its fieldsThe swap metric shows the amount of swap space that is currently being used and the amount of swap space that is available for use Swap also known as virtual memory is a mechanism that enables computer systems to use extra memory by creating a file or partition on a storage volume This serves as a backup option when the system s physical RAM is full and can t accommodate new processes The operating system transfers data from RAM to the swap space allowing the system to continue running smoothly The swap metric also includes several fields that give an overview of the system s memory usage such as total The size of the swap partition or swap fileused The amount of swap space in usefree The remaining unused swap spaceReferring back to the previous output gotten when the free command was run the output fields for swap resulted as zero This entails that there is no swap space made available on the system Free command optionsThe free command can be tailored to show memory usage in any desired format To get the memory information in bytes add the b option to the commanduser ubuntu free b total used free sharedbuff cache availableMem Swap To get the memory information in kilobytes add the k option to the command When the free command is used alone as was demonstrated earlier without any option the default displayed of the memory is in kilobytes user ubuntu free kTo view the memory information in megabytes add the m option to the commanduser ubuntu free m total used free shared buff cache availableMem Swap To view the memory information in gigabytes add the g option to the commanduser ubuntu free g total used free shared buff cache availableMem Swap To view the memory information in human readeable format add the h option to the commanduser ubuntu free h total used free shared buff cache availableMem Gi Mi Gi Mi Gi GiSwap B B B Benefits of the free command in LinuxThe free command is an invaluable tool for managing and monitoring memory usage In this section we will delve into the benefits of utilizing this command Display current memory usageRunning the free command without any arguments will display the current amount of used and available memory on the system as well as the amount of memory being used for system buffers and disk cache This helps you to know processes eating up your systems storage Monitor memory usage over timeBy using the free command in combination with the watch command you can display the current memory usage at regular intervals For example watch n free m will display the current memory usage every seconds This can be useful for identifying patterns in memory usage over time Identify memory leaksIf the used column of the free command output is consistently high it may indicate a memory leak in one of the running programs By running the command periodically and checking the used memory you can identify the process that s causing the leak Check for high buffer cache usageIf the buffers and cached columns are consistently high it may indicate that the system is using a lot of memory for caching While this is generally not a problem it can cause slow performance if the system is low on memory Display memory usage in different unitsBy using the m or g options you can display the memory usage in megabytes or gigabytes respectively Comparison with other command line toolsThe free command can be used in conjunction with other command line tools like top htop and vmstat to provide a more complete picture of the system s memory usage and performance ConclusionIn this article we discussed the free command how it works and its benefits The free command in Linux is a useful tool for monitoring the system s memory usage as well as a valuable tool for managing and optimizing the performance of Linux systems Understanding the output of the free command can help administrators and users identify potential memory bottlenecks and troubleshoot performance issues |
2023-04-04 04:30:29 |
海外科学 |
NYT > Science |
Highlights From NASA’s Reveal of the Artemis II Moon Astronauts |
https://www.nytimes.com/live/2023/04/03/science/artemis-nasa-news
|
artemis |
2023-04-04 04:23:04 |
海外科学 |
NYT > Science |
California Salmon Stocks Are Crashing. A Fishing Ban Looks Certain. |
https://www.nytimes.com/2023/04/03/climate/salmon-fishery-closed-california.html
|
California Salmon Stocks Are Crashing A Fishing Ban Looks Certain Scientists say alarming declines at the southern end of the fishes range may be a sign of what s to come as waters warm farther north |
2023-04-04 04:20:38 |
ニュース |
BBC News - Home |
Social care reform funding halved for England, government confirms |
https://www.bbc.co.uk/news/uk-65171795?at_medium=RSS&at_campaign=KARANGA
|
confirmsmoney |
2023-04-04 04:32:52 |
ニュース |
BBC News - Home |
Climate change: Catalonia in grip of worst drought in decades |
https://www.bbc.co.uk/news/world-europe-65129735?at_medium=RSS&at_campaign=KARANGA
|
northern |
2023-04-04 04:09:44 |
IT |
週刊アスキー |
新宿区にイオンフードスタイルが初出店! 「イオンフードスタイル西新宿店」4月15日オープン |
https://weekly.ascii.jp/elem/000/004/131/4131368/
|
西新宿 |
2023-04-04 13:30:00 |
IT |
週刊アスキー |
ココス、「ミュゼ ドゥ ショコラテオブロマ」監修「ショコラデザートフェア」4月13日開催 |
https://weekly.ascii.jp/elem/000/004/131/4131386/
|
土屋公二 |
2023-04-04 13:30:00 |
IT |
週刊アスキー |
ツイッター、ロゴを柴犬に変更 マスクCEO「約束」守る |
https://weekly.ascii.jp/elem/000/004/131/4131388/
|
暗号通貨 |
2023-04-04 13:15:00 |
IT |
週刊アスキー |
魁力屋×ローソンのコラボ第6弾! 焼きラーメンや背脂醤油ラーメンなどが登場 |
https://weekly.ascii.jp/elem/000/004/131/4131384/
|
焼きラーメン |
2023-04-04 13:10:00 |
マーケティング |
AdverTimes |
4月1日を「ほぼカニの日」に制定 楽しい“ウソ”掲げコラボキャンペーン展開 |
https://www.advertimes.com/20230404/article415651/
|
日本記念日協会 |
2023-04-04 04:39:42 |
海外TECH |
reddit |
[Post Game Thread] Light That Baby Up! Angels defeat Mariners! |
https://www.reddit.com/r/angelsbaseball/comments/12b9045/post_game_thread_light_that_baby_up_angels_defeat/
|
Post Game Thread Light That Baby Up Angels defeat Mariners Angels Mariners First Pitch PM at T Mobile Park Team Starter TV Radio Angels Reid Detmers ERA BSW KLAA KWKW ES Mariners George Kirby ERA RSNW KIRO Game Preview r angelsbaseball Discord Reddit Stream for this post Line Score Game Over R H E LOB LAA SEA Box Score SEA AB R H RBI BB SO BA CF Rodríguez Ju B France RF Hernández T B Suárez E LF Pollock B Haggerty C Murphy To DH Hummel PH La Stella SS Crawford J SEA IP H R ER BB SO P S ERA Kirby Murfee Castillo D Festa LAA AB R H RBI BB SO BA LF Ward CF Trout DH Ohtani RF Renfroe B Lamb SS Fletcher Da B Drury B Urshela B Rengifo C O Hoppe LAA IP H R ER BB SO P S ERA Detmers Tepera Moore Herget Quijada Estévez Scoring Plays Inning Event Score B Eugenio Suarez doubles on a line drive to left fielder Taylor Ward Julio Rodriguez scores T Luis Rengifo singles on a line drive to left fielder AJ Pollock Jake Lamb scores Brandon Drury to nd B Ty France doubles on a line drive to right fielder Hunter Renfroe Julio Rodriguez scores T Luis Rengifo singles on a sharp line drive to right fielder Teoscar Hernandez Jake Lamb scores Brandon Drury to nd T Shohei Ohtani homers on a fly ball to center field Mike Trout scores B Eugenio Suarez singles on a line drive to center fielder Mike Trout J P Crawford scores Julio Rodriguez to rd T Taylor Ward homers on a fly ball to center field Luis Rengifo scores T Brandon Drury doubles on a sharp line drive to center fielder Julio Rodriguez Hunter Renfroe scores Highlights Description Length Video Eugenio Suárez ropes an RBI double into left field Video Luis Rengifo lines an RBI single into left field Video Ty France crushes an RBI double into left field Video Ty France steals second base for his first MLB steal Video Luis Rengifo drills his second RBI single Video Shohei Ohtani launches a two run home run Video Breaking down George Kirby s pitches Video Breaking down Shohei Ohtani s home run Video Eugenio Suárez lines an RBI single to center field Video Breaking down Reid Detmers s pitches Video Reid Detmers s outing against the Mariners Video George Kirby whiffs five vs Los Angeles Video Shohei Ohtani s two run homer Creator Cuts Video Reid Detmers fans seven over innings Video J P Crawford makes a nifty glove flip to second base Video Taylor Ward crushes a two run home run to center Video The distance behind Taylor Ward s home run Video Shohei Ohtani bows to Ichiro before the game Video Brandon Drury lines an RBI double to left center Video Decisions Winning Pitcher Losing Pitcher Save Tepera ERA Kirby ERA Game ended at PM submitted by u angelsbaseball to r angelsbaseball link comments |
2023-04-04 04:32:18 |
コメント
コメントを投稿