diff --git a/docs/store/index.js b/docs/store/index.js new file mode 100644 index 000000000..2c01d47fa --- /dev/null +++ b/docs/store/index.js @@ -0,0 +1,15 @@ +export const actions = { + async nuxtServerInit ({ commit }, { $content }) { + try { + const index = await $content("guide").only(["title"]).fetch(); + const children = index.map((o) => ({ + component: "NuxtLink", + text: o.title, + props: { to: o.path }, + })); + commit("addMenuChildren", { children, parent: "/guide" }); + } catch (err) { + console.log(err) + } + } +} diff --git a/docs/store/mutations.js b/docs/store/mutations.js index bb5f04545..4c5e277e8 100644 --- a/docs/store/mutations.js +++ b/docs/store/mutations.js @@ -1,4 +1,9 @@ export default { + addMenuChildren(state, { children, parent }) { + const index = state.menu.findIndex((o) => o.props.to === parent) + state.menu[index].children = children + }, + // TODO: add ability to pin items // TODO: add support for page titles addRecent(state, link) { diff --git a/docs/store/state.js b/docs/store/state.js index 217e5dc38..ce19f48fb 100644 --- a/docs/store/state.js +++ b/docs/store/state.js @@ -4,16 +4,19 @@ export default () => ({ component: "NuxtLink", text: "Home", props: { to: "/" }, + children: [], }, { component: "NuxtLink", text: "API", props: { to: "/api" }, + children: [], }, { component: "NuxtLink", text: "Guide", props: { to: "/guide" }, + children: [], }, { component: "a", @@ -23,6 +26,7 @@ export default () => ({ href: "https://github.com/druxt/druxt.js", target: "_blank", }, + children: [], }], // Package list.