Jason Thomas

Jason Thomas

1561104240

Building a JAMstack website with Cosmic JS

In this tutorial, you’ll learn how to build a JAMstack website using Vue.js, Nuxt.js and Cosmic JS

Let’s first define our JAMstack: ‘J’ stands for JavaScript, our application uses Vue.js. ‘A’ stands for APIs, and we are using the powerful APIs of Cosmic JS. ‘M’ stands for Markup, which is Nuxt.js in this example. For this tutorial, we will be building a simple fitness studio website. In the end, we will deploy it on Netlify which gives serverless backend services and hosting. Let’s get started.

TL;DR

Checkout the demo

Download the codebase

Introduction

We are building a **JAMstack **website with the powerful APIs of Cosmic JS. This website is about fitness and the body. The first page is dynamic with some navigations provided by Vue.js. On the left side navigation, you will find the link to the blog, whose data is also coming from the Cosmic JS via the Cosmic JS APIs. Let’s start now with the requirements.

Requirements

The one and the only requirement is Node.js. Install it on your system to run npm commands.

Getting Started

Here we are using npm but you can also use yarn to install packages. So if you have installed above software, run the following command to a quick start:

npx create-nuxt-app jamstack_app

Here jamstack_app is your desired name of the app. Now go to the root of the created folder, and run the following command to run it in development:

npm run dev

Now visit: http://localhost:3000/ to view the project in development mode.

Learn more about Nuxt.js quick starter kit here: Nuxt.js Starter Kit

Folder Structure

After creating the app, you will get the same folder structure as given in the picture:

Let’s explain the main folders and files of this structure. package.json file contains the record of all modules installed in your project. Static folder contains the static files used in the project like logo and images. Pages folder contains the pages like home page and blog etc. node_modules has all modules installed and layout contains styling of the project. Config folder is created by us to save the config.js file which will be used at the time dynamic requests to the Cosmic JS server.

Configuration

We have generated the Nuxt.js app with the app generator but the main configuration is pending to make our app a complete JAMstack app. With the creation of the app, JavaScript and Markup part of the app completed. Now we are configuring the API part of the app that means the Cosmic JS part.

For this, you need a Cosmic JS account. Sign up for Cosmic JS official website, it is totally free. Then create a free bucket and create your first object type: ‘blogs’. Or you can import a built-in bucket, way to import it is given in the below heading.

Now click the basic setting option in your dashboard, it will open your basic setting page as shown above. Note down your bucket slug, bucket_id. Now generate the read and write keys and save them on your computer. Now save them in your project also. For this create a config folder and create a config.js file in it and save as given below:

const config = {
    
bucket_name: "jamstack_app",
bucket_slug: "jamstack_app",
bucket_id: "YOUR COSMIC BUCKET_ID",
read_key: "YOUR COSMIC READ_KEY",
write_key: "YOUR COSMIC WRITE_KEY",
url: "https://api.cosmicjs.com/v1/"

}
export default config;

In-built Bucket

If you don’t want to create a new bucket, then you have an option to import a readymade bucket. For this, download the bucket.json file from our Git codebase and import it from your dashboard from the Import/Export option, check below image for visual help:

Home Page

Let’s get started with the first page that is the home page. In this we will render the dynamic data from Cosmic JS server with APIs, it will show you the Vue.js part of the website. Here we are going to write the detail of our website and will implement navigation in the header of the website as well as in the bottom part will give a button to navigate to blog. Check out the code of homepage at location: pages/index.vue


<template>
  <v-layout column justify-center align-center>
    <v-flex xs12 sm8 md6>
      <div class="text-xs-center">
      </div>
      <v-card>
        <v-card-title class="headline"><h2>{{title}}</h2></v-card-title>
        <v-card-text>
          <div v-html="body"></div>
          <br>
          <img
          :src="`${image}`"
          alt="Fitness"
          class="mb-5"
      >

          <hr class="my-3">
          
          <div class='float-left'><p><b>About us</b></p><div v-html="about"></div></div>

          <div class='float-right'><p><b>Contact us</b></p><div v-html="contact"></div></div>
        </v-card-text>
        <v-card-actions>
          <v-spacer/>
          <v-btn color="primary" flat nuxt to="/blog">Read Blog</v-btn>
        </v-card-actions>
      </v-card>
    </v-flex>
  </v-layout>
</template>

<style>
.float-left {
  float: left
}
.float-right {
  margin-left: 300px
}
</style>
<script>
import axios from "axios";
import config from '../config/config';
export default {
  asyncData (context) {
    return axios.get(config.url + config.bucket_slug + '/object-type/homes',{
            params: {
                read_key: config.read_key
            }
        })
      .then(res => {
        return {title : res.data.objects[0].title, body: res.data.objects[0].content, image: res.data.objects[0].metadata.image, about: res.data.objects[0].metadata.about_us, contact: res.data.objects[0].metadata.contact_us}
      });
  }
};
        
</script>

This page is a template plus vue.js code and pure dynamic in nature. Here we applied a link at the bottom which navigates to the blog page and this blog page is also pure dynamic in nature.

The Layout of the Website

The complete layout of the app is coded in a single file for good structure. Here we are customizing the header, footer and other color schemes of the app. Check out the code for layout layouts/default.vue

<template>
  <v-app dark>
    <v-navigation-drawer
      v-model="drawer"
      :mini-variant="miniVariant"
      :clipped="clipped"
      fixed
      app
    >
      <v-list>
        <v-list-tile
          v-for="(item, i) in items"
          :key="i"
          :to="item.to"
          router
          exact
        >
          <v-list-tile-action>
            <v-icon>{{ item.icon }}</v-icon>
          </v-list-tile-action>
          <v-list-tile-content>
            <v-list-tile-title v-text="item.title" />
          </v-list-tile-content>
        </v-list-tile>
      </v-list>
    </v-navigation-drawer>
    <v-toolbar
      :clipped-left="clipped"
      fixed
      app
    >
      <v-toolbar-side-icon @click="drawer = !drawer" />
      
      <v-toolbar-title to="/"><v-btn to="/">JAMstack Website using Vue.js, Nuxt.js and Cosmic JS</v-btn></v-toolbar-title>
      <v-spacer />
      <v-btn
        icon
        @click.stop="rightDrawer = !rightDrawer"
      >
      </v-btn>
    </v-toolbar>
    <v-content>
      <v-container>
        <nuxt />
      </v-container>
    </v-content>
    <v-footer
      :fixed="false"
      app
    >
    <v-layout
      justify-center
      row
      wrap
    >
      <span class='center-align'>Proudly Powered by <a href='https://cosmicjs.com/'>Cosmic JS</a></span>
      </v-layout>
    </v-footer>
  </v-app>
</template>

<script>
export default {
  data() {
    return {
      clipped: false,
      drawer: false,
      fixed: false,
      items: [
        {
          icon: 'apps',
          title: 'Home',
          to: '/'
        },
        {
          icon: 'bubble_chart',
          title: 'Blog',
          to: '/blog'
        }
      ],
      miniVariant: false,
      right: true,
      rightDrawer: false,
      title: 'JAMstack Website using Vue.js, Nuxt.js and Cosmic JS'
    }
  }
}
</script>

<style>
.center-align {
  text-align: center!important
}

</style>

Here we defined the body color of the website along with the header, footer, and navigational effects. In the navigation, we have given route to blog page and route to the home page as well. In the header of the app, we have given navigation to home to the title of the website.

Blog Page

This is the second page of our website, it handles the dynamic fetching of the data from Cosmic JS server with the help of Cosmic JS APIs. First of all, check the code and then we will explain it. Code is placed at the location: pages/blog.vue

<template>
  <v-layout>
    <v-flex text-xs-left>
       <v-btn color="primary" flat nuxt to="/">Back</v-btn>
      <h1>{{title}}</h1><br>
      <div>
      <img
        :src="`${image}`"
        alt="Fitness_quotes"
        class="mb-5"
      >
      </div>
      <div v-html="body"></div>
    </v-flex>
  </v-layout>
</template>
<script>
import axios from "axios";
import config from '../config/config';
export default {
  asyncData (context) {
    return axios.get(config.url + config.bucket_slug + '/object-type/blogs',{
            params: {
                read_key: config.read_key
            }
        })
      .then(res => {
        console.log(res.data.objects[0].metadata.image.url);
        return {title : res.data.objects[0].title, body: res.data.objects[0].content, image:res.data.objects[0].metadata.image.url}
      });
  }
};
        
</script>

There are two part of the page, first is template and second if JavaScript part. In the template, we have given the route to the home page with the back button and rendered the title and body of the blog.

In JavaScript part, we have made of a GET request to the Cosmic JS server with the help of Cosmic JS API. This API is the combination of the static URL, bucket slug and object type. In GET request, read key is necessary to get the data from the server. After a successful request, we manipulated the data and passed to variables as shown in the code.

Static Folder

In the codebase, check out the static folder. As the name describes, it contains the static data and in our case, it contains the static images of our project. As you know our front page id totally static, image shown on the front page resides in this folder. In the same way, any static image or logo which will be used in the project must be placed here.

What Have We Built?

We have built a **JAMstack **website with the powerful APIs of Cosmic JS. In JAMstack:

‘J’ stands for JavaScript and here Vue.js used as JavaScript part of JAM, 'A 'stands for API, here Cosmic JS used as the API part of JAM, Meaning of ‘M’ is Markup, here Nuxt.js is used as the markup. Here the main part is the API part, we have made a GET request with the help of which and got the quick response. This request made with the help of axios module and then JSON data manipulated easily. Format of the Cosmic JS API response is very simple to handle.

Deployment to Netlify

We have built an app with Vue.js, Nuxt.js, and Cosmic JS, but it is not a pure JAMstack app until we can deploy the static assets to a CDN. For this example, we will deploy it to the serverless backend service provider Netlify.

Install the Netlify CLI and Nuxt CLI:

npm i -g netlify-cli npm i -g nuxt Build the static files
npm run build

Then deploy to Netlify. You will be prompted to select the folder. Type dist to deploy the dist folder.

netlify deploy

Conclusion

With the help of Cosmic JS you can create powerful applications. In this example, we were able to build a JAMstack application with the API power of Cosmic JS.

#vue-js #javascript #nuxt-js

What is GEEK

Buddha Community

Building a JAMstack website with Cosmic JS

How WordPress Helps you Make Great Websites in 2020

Many sites are powered by a CMS (Content Management System) called WordPress. WordPress is an Open Source Software that offers free use of the product.

This is awesome for a low budget business or individual. To learn more about WordPress or there terms visit their website (wordpress.org).

Before you launch, your WordPress site go through this checklist to get a better understanding

I will assume you have already purchased a domain name and had a hosting account set up with a service provider.

Many service providers are willing to go as far as installing WordPress for you now.

WordPress is great, but you must also learn about how websites work. Beginners should start by learning HTML (HyperText Markup Language) and CSS (Cascading Style Sheets).

These two computer languages basically cover how things are arranged and displayed on a page.

You should also understand how the FTP protocol is used for transferring files to your HTTP server.

Once you have got a good feel of HTML, CSS, HTTP, and FTP you will be ready to start exploring WordPress.

It allows you to change the look and feel of your website through a backside control panel.

You will find that WP is very robust and scalable.

It can provide a solution ranging from a single web page to an expansive multi-page website.

Another cool thing about WP is how it offers database solutions like pages, categories, comments, etc.

You can use it as a Blog or you can create static web pages. I am a huge fan. I have tried JOOMLA, but I still prefer WP.

There is a lot to learn when you are considering building a website.

I have been using WP for about 5 years and I am still learning. There is plenty of documentation available on the net.

If you are in need of a website, and you are starting this from scratch, I would recommend hiring a developer. But if you can accomplish learning this you will be able to build a good website solution for almost anyone.

#wordpress #wordpress-website #web-development #wordpress-website-building #wordpress-website-development #wordpress-tutorial #website #website-development

Rahim Makhani

Rahim Makhani

1620968589

Get a Bug Free and smooth website with website Maintenance

Having a website for your own firm or business is very important as it can benefit you in many ways like your users can get 24/7 service from your company, you can exchange your information, it can help you to expand your business in the market. One must also maintain their website to keep it bug free and updated.

Your website should be bug free because if there is any bug in your website it will slow down the performance of it and will not even work properly if this happens then there are chances that you may lose your customers.

Are you searching for a company that can provide you with website support and maintenance? Nevina Infotech is the best company that can help you with the maintenance and support, as we have enthusiastic web app developers who can help you to maintain your website.

#website maintenance services #website support and maintenance #website maintenance support #website maintenance packages #website maintenance company #website maintenance plans

Security Website Design

As web developers, we strive to meet your specific needs by creating a website that is user-friendly and remains relevant to the current design trends. This ensures that your website grabs the attention of your audience and keeps you ahead of your competitors.

DataIT Solutions team of experts works collaboratively to create ideas that can meet your requirements. Our Website Designing Company believes in High-Quality Professional Website Designing for your Security Website Designing. Our designers have experience in working on a wide array of projects, including websites of the next generation. We listen to your needs and then deliver.

Our Expertise includes:

  • Dot Net Development
  • PHP Development
  • HTML5 Development
  • IOS App Development
  • Android App Development
  • Website Security services

Our team of experts has the expertise, knowledge, and skills to take control and dominate the web design industry over the next couple of years. They are on hand to listen to your ideas, goals, and help you to have a website that is unique and works with your business and brand.

Looking for a better design? Need a professional web design?
Get in touch with our, Web Design Professional experts.

#security website design #security website designing #security website designer #website designer #website designing #website design

Construction website design in the UK

The right construction web design firm can help ensure that a website converts visitors into clients or leads effectively, even on the first visit, through the proper use of site elements to lead visitors through a sales funnel. With an effective website, construction companies can easily showcase their portfolios as they work to generate more effective leads.

DataIT Solutions offers customized construction website design companies in the UK and digital marketing services. Whether you’re establishing a new online location or your current site needs a redesign, we work with you to produce exactly what you want and need.

We approach every project differently - we analyze and research your business and customer type to build and design the website around our analysis and what we feel will work best for your website and business and as standard, a website will benefit from all of the standard content management features.

What’s included in your website design packages:

  • Hosting and coding
  • Graphic design
  • Advanced analytics tracking
  • Optimization for SEO
  • Existing content import
  • New content creation
  • Lead form creation and tracking
  • Website compatibility across all browsers and devices
  • Integration with social media pages
  • XML sitemap creation and submission
  • And more!

Ready to start your website design project?
We’ll consult with you to scope out your website build requirements.
Request a Consultation.!!

#construction website design in the uk #construction website design #construction website #website design in the uk #website design #website designer

How to build an Elearning app or website like Coursera

E-learning has completely changed the education industry, specifically in the time of COVID-19. With the increased use of online learning apps, there is a huge growth opportunity that lies ahead for some of the industry.

Developing an e-learning app requires extensive experience in coding. If you are looking to develop an e-learning app, WebClues Infotech is the perfect company to guide you at every step including the Concept, Business Plan, Launch, Revenue Generation, and Support.

To know more about How you can develop and what is the cost to develop e-learning apps like Coursera read our blog How to build an E-learning app or website like Coursera

#how to build an e learning website like coursera #how much would it cost to create a website like coursera #cost of website like coursera #how to make an app like coursera #how to create a website like coursera #e learning website cost