GithubHelp home page GithubHelp logo

gtodua / sample-app-vue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kontent-ai/sample-app-vue

0.0 0.0 0.0 3.22 MB

A sample website written in JavaScript and Vue utilizing the Kontent Delivery API to manage and retrieve content.

Home Page: https://kontent-sample-app-vue.netlify.app

License: MIT License

JavaScript 3.86% CSS 66.01% HTML 0.37% Vue 29.76%

sample-app-vue's Introduction

Kontent.ai sample Vue.js single-page application

Netlify Status Live Demo Stack Overflow Discord

This is a sample website written in JavaScript utilizing the Kontent.ai Delivery API to retrieve content. You can register your account for free at https://app.kontent.ai.

Application setup

  1. Install the latest version of NodeJS and npm. You can download both at https://nodejs.org/en/download/.
  2. Clone the sample application repository.
  3. Navigate to the root folder of the application in the command line.
  4. Type npm install to install required npm packages.
  5. Type npm run serve to start a development server.
  6. The application opens in your browser at http://localhost:8080.

Data origin

This sample wants to showcase either loading content from Kontent.ai as well as loading some part of the site from static JSON resources.

Basically, the content that you can't find in the Localization folder is loaded from Kontent.ai.

  • The data provided from Localization are using the vue-i18n plugin, so every call in components using $t('KEYWORD') in components is loading data from these JSONs as "Banner" section" (component here)

Data fetching

This solution fetches data using the Delivery client. For more implementation detail on how to set up the client see src/Client.js. After your client is set up, you are able to deliver your content to your project. The following example showcases how to use a Kontent.ai delivery client to fetch data.

fetchBrewer: function () {
  var query = Client.items()
    .type('brewer')
    .equalsFilter('url_pattern', this.$route.params.brewerSlug)

  if(this.language) {
    query.languageParameter(this.language)
  }

  query
    .toPromise()
    .then(response => {
      // store data to the state variable of your component.
      this.brewer = response.data.items[0]
    }
}

Language fallbacks

To deal with content that is not available in the current language, this project uses a method called language fallbacks. It will fetch the content in the language set as a fallback language in the Kontent.ai project and redirect the website to the URL with a prefix of the given language. However, it is possible to disable language fallbacks by adding a filter of system.language to your query. For more information about getting localized content check this link.

var query = Client.items().type('about_us');

if (this.language) {
    query
    .languageParameter(this.language)
    .equalsFilter('system.language', 'es-ES');
}

Connecting to your sample project

On the first run of the app, you'll be presented with a configuration page. It will allow you to connect the app to your Kontent.ai sample project or create a new one. You'll also be able to start a trial and convert to a developer plan when the trial expires.

If you want to open the configuration page after the project is already connected to the app. Just open the URL http://localhost:8080/Admin/Configuration.

Alternatively, you can connect your project manually as per the chapter below.

Connecting to your project manually

If you want to change the source Kontent.ai project, follow these steps:

  1. In Kontent.ai, choose Project settings from the app menu.
  2. Under Production environment settings, choose API keys.
  3. Copy your Project ID.
  4. Create and open a .env.local file in the sample application folder.
  5. On the first line, add your Project ID constant using the format VUE_APP_PROJECT_ID=00000000-0000-0000-0000-000000000000.
  6. Save the file.

When you now run the application, it will retrieve the content from your sample project. This setup has a higher priority than setting your sample project via the Configuration page.

Previewing content from your project

To preview unpublished content in the sample application, follow these steps:

  1. In Kontent.ai, choose Project settings from the app menu.
  2. Under Production environment settings, choose API keys.
  3. Copy your Project ID and Preview API key.
  4. Create and open a .env.local file in the sample application folder.
  5. On the first line, add your Project ID constant using the format VUE_APP_PROJECT_ID=00000000-0000-0000-0000-000000000000.
  6. On the next line, add your Preview API key using the format VUE_APP_PREVIEW_API_KEY=00000000-0000-0000-0000-000000000000.
  7. Save the file.

When you now run the application, you will see all project content including the unpublished version of content items.

Content administration

  1. Navigate to https://app.kontent.ai in your browser.
  2. Sign in with your credentials.
  3. Manage content in the content administration interface of your sample project.

You can learn more about content editing at Kontent.ai Learn.

Content delivery

You can retrieve content either through the Kontent.ai Delivery SDKs or the Kontent.ai Delivery API:

  • For published content, use https://deliver.kontent.ai/PROJECT_ID/items.
  • For unpublished content, use https://preview-deliver.kontent.ai/PROJECT_ID/items.

For more info about the API, see the API reference.

You can find the Delivery and other SDKs at https://github.com/kontent-ai.

Deployment

You can use, for example, surge to deploy your app live. Check out the step-by-step guide on our blog.

sample-app-vue's People

Contributors

simply007 avatar martinekv avatar petrsvihlik avatar dependabot-preview[bot] avatar fluffynuts avatar liamgold avatar maximekoitsalu avatar dependabot[bot] avatar vlmar avatar caseydbrown avatar juraju-kentico avatar vlastimilm avatar colliercz avatar jancerman avatar kentico-michaelb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.