qiskit.org/nuxt.config.ts

239 lines
5.9 KiB
TypeScript
Raw Normal View History

2019-06-06 23:12:57 +08:00
import path from 'path'
import fs from 'fs'
2020-04-08 15:48:46 +08:00
import consola from 'consola'
import markdownIt from 'markdown-it'
import miLinkAttributes from 'markdown-it-link-attributes'
import miAnchor from 'markdown-it-anchor'
import uslug from 'uslug'
import Mode from 'frontmatter-markdown-loader/mode'
import { Configuration } from '@nuxt/types'
import pkg from './package.json'
2020-04-08 15:48:46 +08:00
import fetchEvents from './hooks/update-events'
const { NODE_ENV, SHOW_COOKIES_SETTINGS, GENERATE_CONTENT, AIRTABLE_API_KEY } = process.env
const IS_PRODUCTION = NODE_ENV === 'production'
2019-06-06 14:30:22 +08:00
const md = markdownIt({
linkify: true,
html: true
})
md.use(miLinkAttributes, {
pattern: /^https?:/,
attrs: {
target: '_blank',
rel: 'noopener'
}
})
md.use(miAnchor, {
2019-12-05 21:24:45 +08:00
slugify (id) { return uslug(id) }
})
const config: Configuration = {
Redesign and Qiskit.org integration (#67) --- New software version notes: This commit updates to Nuxt 2.9.2. The new version has some implications when coming from 2.8.X version using Typescript: https://typescript.nuxtjs.org/migration.html Due to this bug: https://github.com/markmarkoh/datamaps/pull/500 A custom version of datamaps is used for rendering the Advocate Map: https://github.com/delapuente/datamaps/tree/fix-types --- The new theme makes extensive use of dark and electric colors with a vibrant header, combining different styles of sections with ad-hoc widgets to showcase the capabilities of the design. Affected pages are `/education` and `/advocates`. The new design integrates with qiskit.org by faking the top menu and adding an internal community sub-menu. It also adds a footer with Qiskit elements, community sub-sections and social media. This commit adds a new component structure aimed at creating a collection of highly composable units. These units use BEM for internal styling. It is recommended not to style the components outside their physical boundaries to give the page freedom to integrates. However, the CSS framework (which is now SCSS) provide a collection of mixin for standarizing the layout. The point of entry for the community is redirecting to the education micro-site on purpose. This commit intentionally breaks the separation between design and presentation. A better approach is needed to allow content documents to be able of providing several HTML sections instead of only one. A summary of the problem can be found at: https://michaelnthiessen.com/advanced-vue-controlling-parent-slots The most semantic solution, [portals](https://github.com/LinusBorg/portal-vue), don't work in server-side rendering mode and so, the portals are not populated with content in a static-site configuration. We are exploring embedding multiple front-matter documents at: https://github.com/delapuente/frontmatter-markdown-loader/tree/multiple The other solutions also rely on client reactivity which is not the desired behaviour. The new design also intentionally avoids the use of the `<nuxt-link>` component. Due to unknown reasons, DOM differentiation does not work correctly and the navigation is ultimately broken. Follow-ups for solving the navigation issues, improve reactivity in secondary content and recover the separation between design and content are filled in the project repository.
2019-09-05 16:06:14 +08:00
mode: 'universal',
env: {
2020-04-08 15:48:46 +08:00
analyticsScriptUrl: IS_PRODUCTION
? 'https://cloud.ibm.com/analytics/build/bluemix-analytics.min.js'
: 'https://dev.console.test.cloud.ibm.com/analytics/build/bluemix-analytics.min.js',
analyticsKey: IS_PRODUCTION
? 'ffdYLviQze3kzomaINXNk6NwpY9LlXcw'
: 'zbHWEXPUfXm0K6C7HbegwB5ewDEC8o1H'
},
2019-06-06 14:30:22 +08:00
/*
** Headers of the page
*/
head: {
title: pkg.name,
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: pkg.description }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
2019-06-06 14:30:22 +08:00
},
/*
** Customize the progress-bar color
*/
loading: { color: '#fff' },
/*
** Global CSS
*/
css: [
'~/static/css/fonts.css'
2019-06-06 14:30:22 +08:00
],
/*
** Plugins to load before mounting the App.
2019-06-06 14:30:22 +08:00
*/
plugins: [
'~/plugins/router-hooks.ts',
2020-03-02 16:40:57 +08:00
'~/plugins/highlight-js.ts',
'~/plugins/carbon.ts',
'~/plugins/deep-load.ts',
{
src: IS_PRODUCTION || SHOW_COOKIES_SETTINGS
? '~/plugins/hotjar.ts'
: '',
mode: 'client'
},
{
src: IS_PRODUCTION || SHOW_COOKIES_SETTINGS
? '~/plugins/segment-analytics.ts'
: '',
mode: 'client'
}
2019-06-06 14:30:22 +08:00
],
/*
** Nuxt.js modules
*/
modules: [
'@nuxtjs/style-resources',
'@nuxtjs/axios'
2019-06-06 14:30:22 +08:00
],
styleResources: {
/*
** Do not include styles! Only variables, mixins and functions.
*/
scss: [
'./assets/scss/mq.scss',
'./assets/scss/mixins.scss',
'./assets/scss/carbon/community-theme.scss'
]
},
2019-08-31 23:28:28 +08:00
/*
** Migrating from Nuxt 2.8.x to 2.9.y
** https://typescript.nuxtjs.org/migration.html
*/
buildModules: [
['@nuxt/typescript-build', {
typeCheck: true,
ignoreNotFoundWarnings: true
}]
],
2019-06-06 14:30:22 +08:00
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
2019-12-05 21:24:45 +08:00
extend (config) {
config.module = config.module || { rules: [] }
2019-06-06 23:12:57 +08:00
config.module.rules.push({
test: /\.md$/,
loader: 'frontmatter-markdown-loader',
include: path.resolve(__dirname, 'content'),
2019-06-06 23:12:57 +08:00
options: {
mode: [Mode.VUE_RENDER_FUNCTIONS, Mode.VUE_COMPONENT, Mode.HTML],
2019-06-06 23:12:57 +08:00
vue: {
root: 'content'
},
markdown: (body) => {
return md.render(body)
2019-06-06 23:12:57 +08:00
}
}
})
2019-06-25 04:23:22 +08:00
},
// TODO: Workaround for dealing with. Remove once its solved:
// https://github.com/nuxt/nuxt.js/issues/3877
splitChunks: {
layouts: true
2019-06-06 14:30:22 +08:00
}
},
router: {
scrollBehavior (to, from) {
const nuxt = window.$nuxt
// Force `triggerScroll` when navigating through the page.
// Did not found the event `triggerScroll` documented but it is used in
// the default behaviour to ensure the page has loaded:
// https://github.com/nuxt/nuxt.js/blob/e3ba6c290dd60e1a8c5b7daec72982a667a7fe04/packages/vue-app/template/router.scrollBehavior.js
if (to.path === from.path && to.hash !== from.hash) {
nuxt.$nextTick(() => nuxt.$emit('triggerScroll'))
}
return new Promise((resolve) => {
nuxt.$once('triggerScroll', () => {
if (!to.hash) {
return resolve()
}
const el: HTMLElement | null = document.querySelector(to.hash)
if (!el) {
console.warn('Trying to navigate to a missing element', to.hash)
return resolve()
}
if ('scrollBehavior' in document.documentElement.style) {
window.scrollTo({ top: el.offsetTop, behavior: 'smooth' })
} else {
window.scrollTo(0, el.offsetTop)
}
return resolve()
})
})
}
},
generate: {
routes: (function () {
const events = getContentUrls('events')
2020-05-21 22:26:56 +08:00
return events
function getContentUrls (contentRoot: string): string[] {
return fs.readdirSync(path.resolve(__dirname, 'content', contentRoot))
.filter(isContentAndNotReadme)
.map(toContentUrl(contentRoot))
}
function isContentAndNotReadme (filename: string): boolean {
return path.extname(filename) === '.md' &&
path.parse(filename).name.toUpperCase() !== 'README'
}
function toContentUrl (contentRoot: string): (s: string) => string {
return (filename: string): string => {
return `/${contentRoot}/${path.parse(filename).name}`
}
}
})()
},
hooks: {
build: {
async before () {
2020-04-08 15:48:46 +08:00
if (!IS_PRODUCTION && !GENERATE_CONTENT) {
console.warn('Skipping content generation. Set GENERATE_CONTENT to enable it.')
return
}
await generateContent()
}
}
2019-06-06 14:30:22 +08:00
}
}
2020-04-08 15:48:46 +08:00
async function generateContent () {
if (AIRTABLE_API_KEY) {
consola.info('Generating community event previews')
await fetchEvents(AIRTABLE_API_KEY, './content/events')
} else {
consola.warn('Cannot generate events: missing AIRTABLE_API_KEY environment variable')
}
}
export default config