qiskit.org/nuxt.config.ts

246 lines
5.7 KiB
TypeScript
Raw Normal View History

/// <reference path="types/index.d.ts" />
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 { NuxtConfig } from '@nuxt/types'
import pkg from './package.json'
2020-04-08 15:48:46 +08:00
import fetchEvents from './hooks/update-events'
import fetchAdvocates from './hooks/update-advocates'
import fetchEcosystemMembers from './hooks/update-ecosystem'
2020-04-08 15:48:46 +08:00
const {
NODE_ENV,
ENABLE_ANALYTICS,
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, {
slugify (id: any) { return uslug(id) }
})
const config: NuxtConfig = {
2021-10-25 21:00:13 +08:00
target: 'static',
feat: learn page v2 (#2574) * add prereq content * add img * add course page images * add correct links * capitalize Notebooks * add quantum states and qubits content * fix segment value * add recommended references, small fix to list spacing * add multiple qubit and entanglement content * added external recommendations content * add quantum protocols and quantum algorithms content * add quantum protocols and quantum algorithms content * fix lint error * update external recommended links * add investigating quantum hardware content * renaming to avoid collisions * add Investigating Quantum Hardware Using Quantum Circuits content * New learn content for q algorithms for apps * Added tutorials section * Added other platforms content * Added URLs for the tutorials * Fixed a typo between simple and sample * Improved images from tutorials * Added the texts for youtube and medium * Fixed typos * Added bonus level to textbook pages * Removed q-system-error-analysis card * changed order * description can use the whole space from the beggining instead of grow from bottom * better title height * updated sections and quantum lab thumbnail (#2590) * add Quantum Computing Labs content * fix: learn content consistent thumbnails (#2597) * Add chapters section to learn page * remove overview page header grid * undo renaming * change heading * feat: add new helpful resource tile (#2618) * update external readings links * update cta and intro page * migrate textbook-beta route and components to /learn * remove new-content from copy script * implement mega-menu-dropdown web component * readd segment attributes * use new web-component and clean up component html * fix section title * 2021 QGSS URL fix * fix: consistent thumbnail sizes (#2650) * use latest wc package * update @qiskit/web-components and use of mega-dropdown-menu Co-authored-by: @techtolentino Co-authored-by: //va <vabarbosa@users.noreply.github.com> Co-authored-by: David <9059044+Tansito@users.noreply.github.com> Co-authored-by: Gregorio Iniesta <korgan00@gmail.com> Co-authored-by: Chris Fisher <clfshr@gmail.com>
2022-06-09 21:12:03 +08:00
// Disable Server Side rendering
ssr: false,
// Inline server bundle dependencies
standalone: true,
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'
},
publicRuntimeConfig: {
baseURL: IS_PRODUCTION
? 'https://qiskit.org'
: 'localhost:3000'
},
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: https://go.nuxtjs.dev/config-css
2019-06-06 14:30:22 +08:00
css: [
'~/assets/scss/main.scss'
2019-06-06 14:30:22 +08:00
],
/*
** Content
*/
content: {
dir: 'new-content'
},
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',
'~/plugins/carbon.ts',
'~/plugins/deep-load.ts',
{ src: '~/plugins/hotjar.ts', mode: 'client' },
...optional(
IS_PRODUCTION || ENABLE_ANALYTICS,
{ src: '~/plugins/segment-analytics.ts', mode: 'client' } as const
)
2019-06-06 14:30:22 +08:00
],
/*
** Nuxt.js modules
*/
modules: [
'@nuxt/content'
2019-06-06 14:30:22 +08:00
],
components: [
{
/* According to https://stackoverflow.com/questions/66336557/nuxt-not-automatically-importing-components-from-nested-directory
** we need to set `pathPrefix: false` to allow the registration of nested directories
*/
path: '~/components',
pathPrefix: false
}
],
// Nuxt Style Resources: @nuxtjs/style-resources
styleResources: {
scss: [
'~/assets/scss/helpers/index.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
}],
'@nuxtjs/style-resources',
// https://go.nuxtjs.dev/stylelint
'@nuxtjs/stylelint-module'
2019-08-31 23:28:28 +08:00
],
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: any) => {
return md.render(body)
2019-06-06 23:12:57 +08:00
}
}
})
feat: learn page v2 (#2574) * add prereq content * add img * add course page images * add correct links * capitalize Notebooks * add quantum states and qubits content * fix segment value * add recommended references, small fix to list spacing * add multiple qubit and entanglement content * added external recommendations content * add quantum protocols and quantum algorithms content * add quantum protocols and quantum algorithms content * fix lint error * update external recommended links * add investigating quantum hardware content * renaming to avoid collisions * add Investigating Quantum Hardware Using Quantum Circuits content * New learn content for q algorithms for apps * Added tutorials section * Added other platforms content * Added URLs for the tutorials * Fixed a typo between simple and sample * Improved images from tutorials * Added the texts for youtube and medium * Fixed typos * Added bonus level to textbook pages * Removed q-system-error-analysis card * changed order * description can use the whole space from the beggining instead of grow from bottom * better title height * updated sections and quantum lab thumbnail (#2590) * add Quantum Computing Labs content * fix: learn content consistent thumbnails (#2597) * Add chapters section to learn page * remove overview page header grid * undo renaming * change heading * feat: add new helpful resource tile (#2618) * update external readings links * update cta and intro page * migrate textbook-beta route and components to /learn * remove new-content from copy script * implement mega-menu-dropdown web component * readd segment attributes * use new web-component and clean up component html * fix section title * 2021 QGSS URL fix * fix: consistent thumbnail sizes (#2650) * use latest wc package * update @qiskit/web-components and use of mega-dropdown-menu Co-authored-by: @techtolentino Co-authored-by: //va <vabarbosa@users.noreply.github.com> Co-authored-by: David <9059044+Tansito@users.noreply.github.com> Co-authored-by: Gregorio Iniesta <korgan00@gmail.com> Co-authored-by: Chris Fisher <clfshr@gmail.com>
2022-06-09 21:12:03 +08:00
config.module.rules.push({
test: /\.js$/,
loader: require.resolve('@open-wc/webpack-import-meta-loader')
})
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
}
},
generate: {
routes: (function () {
const events = getContentUrls('events')
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
}
}
function optional<T> (test: any, ...plugins: T[]): T[] {
return test ? plugins : []
}
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')
consola.info('Generating advocate previews')
await fetchAdvocates(AIRTABLE_API_KEY, './content/advocates')
2020-04-08 15:48:46 +08:00
} else {
consola.warn('Cannot generate events: missing AIRTABLE_API_KEY environment variable')
}
await fetchEcosystemMembers('./content/ecosystem')
2020-04-08 15:48:46 +08:00
}
export default config