Skip to content

Commit

Permalink
feat: sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
albanm committed Jan 6, 2023
1 parent a66f024 commit 2eb6029
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 10 deletions.
11 changes: 8 additions & 3 deletions contract/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,11 @@
},
"footerLinksMode": {
"type": "string",
"default": "columns",
"default": "lines",
"title": "Mode d'affichage des liens",
"oneOf": [
{"title": "en colonnes", "const": "columns"},
{"title": "en lignes", "const": "lines"}
{"title": "en lignes", "const": "lines"},
{"title": "en colonnes", "const": "columns"}
]
},
"footerExtraLogos": {
Expand Down Expand Up @@ -730,6 +730,11 @@
}
},
"default": []
},
"footerSitemap": {
"title": "Ajouter un lien vers le plan du site",
"type": "boolean",
"default": true
}
}
}, {
Expand Down
35 changes: 28 additions & 7 deletions public/components/layout/layout-footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
class="mx-0 my-2"
>
<v-col
v-for="link in config.footerLinks"
v-for="link in footerLinks"
:key="link.title"
cols="10"
sm="4"
Expand All @@ -74,6 +74,12 @@
{{ link.page.title }}
</nuxt-link>
</template>
<nuxt-link
v-else-if="link.type === 'standard'"
:to="link.to"
>
{{ link.title }}
</nuxt-link>
<a
v-else
:href="link.href"
Expand All @@ -86,18 +92,28 @@
>
<v-col class="py-0">
<template
v-for="(link, i) in config.footerLinks"
v-for="(link, i) in footerLinks"
>
<template v-if="link.type === 'internal'">
<nuxt-link
v-if="link.page"
:key="`internal-${i}`"
:to="{name: 'pages-id', params: {id: link.page.id}}"
class="mx-3"
>
{{ link.page.title }}
</nuxt-link>
</template>
<nuxt-link
v-if="link.type === 'internal' && link.page"
:key="`internal-${i}`"
:to="{name: 'pages-id', params: {id: link.page.id}}"
v-else-if="link.type === 'standard'"
:key="`standard-${i}`"
:to="link.to"
class="mx-3"
>
{{ link.page.title }}
{{ link.title }}
</nuxt-link>
<a
v-if="link.type !== 'internal'"
v-else
:key="`external-${i}`"
:href="link.href"
class="mx-3"
Expand Down Expand Up @@ -156,6 +172,11 @@ export default {
}
if (this.config.footerCopyrightAsLogo) logos.push(copyright)
return logos
},
footerLinks () {
const links = [...this.config.footerLinks || []]
if (this.config.footerSitemap) links.push({ type: 'standard', title: 'Plan du site', to: '/sitemap' })
return links
}
}
}
Expand Down
1 change: 1 addition & 0 deletions public/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
...mapState(['config', 'publicUrl', 'portal', 'draft']),
...mapGetters(['footerColor', 'footerColorDark', 'portalHead', 'appBarElevation']),
homeUrl () {
console.log('portal ?', this.portal)
return `${this.publicUrl}/api/v1/portals/${this.portal._id}/assets/home?draft=${this.draft}&hash=${this.config.assets.home && this.config.assets.home.hash}`
}
}
Expand Down
52 changes: 52 additions & 0 deletions public/pages/sitemap.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!-- eslint-disable vue/no-parsing-error -->
<template>
<v-container>
<h2 class="headline grey--text text--darken-3 font-weight-bold mt-6 mb-4">
Plan du site
</h2>
<v-list>
<v-list-item
v-for="page in sitemap"
:key="page.to"
:to="page.to"
class="primary--text"
>
{{ page.title }}
</v-list-item>
</v-list>
</v-container>
</template>

<script>
import { mapState, mapGetters } from 'vuex'

export default {
middleware: 'portal-required',
async fetch () {
const promises = []
if (!this.pages) promises.push(this.$store.dispatch('fetchPages'))
if (!this.datasetsList) promises.push(this.$store.dispatch('fetchDatasetsList'))
if (!this.applicationsList) promises.push(this.$store.dispatch('fetchApplicationsList'))
if (promises.length) await Promise.all(promises)
},
head () {
const title = 'Plan du site - ' + this.config.title
return {
title,
meta: [
{ hid: 'og:url', property: 'og:url', content: this.publicUrl + '/sitemap' },
{ hid: 'og:title', property: 'og:title', content: title },
{ hid: 'og:type', property: 'og:type', content: 'website' }
]
}
},
computed: {
...mapState(['publicUrl', 'config', 'pages', 'datasetsList', 'applicationsList']),
...mapGetters(['sitemap'])
}
}
</script>

<style>

</style>
16 changes: 16 additions & 0 deletions upgrade/scripts/1.34.0/add-default-values.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exports.description = 'Add default values to some new properties'

exports.exec = async (db, debug) => {
const defaultValues = [
['footerSitemap', false]
]
for (const defaultValue of defaultValues) {
for (const configKey of ['config', 'configDraft']) {
const res = await db.collection('portals').updateMany(
{ [`${configKey}.${defaultValue[0]}`]: { $exists: false } },
{ $set: { [`${configKey}.${defaultValue[0]}`]: defaultValue[1] } }
)
debug(`${configKey}.${defaultValue[0]} = ${defaultValue[1]}`, res.result)
}
}
}

0 comments on commit 2eb6029

Please sign in to comment.