{"size": 1492, "ext": "js", "max_stars_repo_path": "store/index.js", "max_stars_repo_name": "galazkatomek/netlify-cms-vue", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "store/index.js", "max_issues_repo_name": "galazkatomek/netlify-cms-vue", "max_issues_repo_issues_event_min_datetime": "2021-03-10T08:27:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T10:43:01.000Z", "max_forks_repo_path": "store/index.js", "max_forks_repo_name": "galazkatomek/netlify-cms-vue", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 26.6428571429, "max_line_length": 97, "alphanum_fraction": 0.5971849866}
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
 
export const state = () => ({
  blogPosts: [],
  galleryImages: [],
  siteInfo: [],
});

export const mutations = {
  setPosts(state, data) {
    state.blogPosts = data;
  },
  setGalleryImages(state, data) {
    state.galleryImages = data;
  },
  setInfo(state, data) {
    state.siteInfo = data;
  },
};
 
const contextToList = (context, contentRoute) => {
  const preparePath = (key) => `/${contentRoute}/${key.replace('.json', '').replace('./', '')}`;
  return context.keys().map(key => ({
    ...context(key),
    _path: preparePath(key)
  }));
};

export const actions = { 
  async nuxtServerInit({ dispatch }) {
    await dispatch('getSiteInfo');
    await dispatch('getBlogPosts');
    await dispatch('getGalleryImages');
  },
  async getBlogPosts({ state, commit }) {
    const context = await require.context('~/content/blog/', false, /\.json$/);

    const searchposts = await contextToList(context, 'blog');
    commit('setPosts', searchposts.reverse());
  },
  async getGalleryImages({ state, commit }) {
    const context = await require.context('~/content/gallery/', false, /\.json$/);

    const galleryImages = await context.keys().map(key => ({
      ...context(key)
    }));
    commit('setGalleryImages', galleryImages);
  },
  getSiteInfo({ state, commit }) {
    const info = require('~/content/setup/info.json');
    commit('setInfo', info);
  }
};
