diff --git a/docs/middleware/recent.js b/docs/middleware/recent.js new file mode 100644 index 000000000..a27d97067 --- /dev/null +++ b/docs/middleware/recent.js @@ -0,0 +1,3 @@ +export default function ({ store, route }) { + store.commit('addRecent', route) +} diff --git a/docs/nuxt.config.js b/docs/nuxt.config.js index d2e223096..99adabf38 100644 --- a/docs/nuxt.config.js +++ b/docs/nuxt.config.js @@ -46,4 +46,8 @@ export default { build: {}, telemetry: true, + + router: { + middleware: 'recent', + } } diff --git a/docs/store/mutations.js b/docs/store/mutations.js new file mode 100644 index 000000000..9d03397e0 --- /dev/null +++ b/docs/store/mutations.js @@ -0,0 +1,16 @@ +export default { + // TODO: add ability to pin items + // TODO: add support for page titles + addRecent(state, route) { + // Filter out current route. + const recent = [...state.recent].filter((o) => o.to !== route.path) + + // Add item. + recent.unshift({ + to: route.path + }) + + // Return only the last 5 items. + state.recent = recent.filter((o, index) => index < 5) + } +} diff --git a/docs/store/state.js b/docs/store/state.js index f396f678f..7ae64ff03 100644 --- a/docs/store/state.js +++ b/docs/store/state.js @@ -1,11 +1,15 @@ export default () => ({ + // Main menu items. menu: [{ title: 'Home', path: '/', }, { - title: 'API', + title: 'API documentation', path: '/api', }], + + // Module list. + // TODO: get this data programatically. modules: [ 'druxt', 'breadcrumb', @@ -16,5 +20,8 @@ export default () => ({ 'schema', 'site', 'views' - ] + ], + + // Recently opened documents. + recent: [], })