Skip to content

Commit

Permalink
Add robots.txt and Prisma syntax highlighting. (#5758)
Browse files Browse the repository at this point in the history
* add robots.txt. Resolves DA-37

* add syntax highlighting for Prisma files. Resolves DA-144
  • Loading branch information
jharrell authored and carlagn committed Apr 1, 2024
1 parent f92142c commit 166650a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/theme/prism-include-languages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import siteConfig from '@generated/docusaurus.config'
import type * as PrismNamespace from 'prismjs'
import type { Optional } from 'utility-types'

export default function prismIncludeLanguages(PrismObject: typeof PrismNamespace): void {
const {
themeConfig: { prism },
} = siteConfig
const { additionalLanguages } = prism as { additionalLanguages: string[] }

// Prism components work on the Prism instance on the window, while prism-
// react-renderer uses its own Prism instance. We temporarily mount the
// instance onto window, import components to enhance it, then remove it to
// avoid polluting global namespace.
// You can mutate PrismObject: registering plugins, deleting languages... As
// long as you don't re-assign it
globalThis.Prism = PrismObject

additionalLanguages.forEach((lang) => {
if (lang === 'php') {
// eslint-disable-next-line global-require
require('prismjs/components/prism-markup-templating.js')
}
// eslint-disable-next-line global-require, import/no-dynamic-require
require(`prismjs/components/prism-${lang}`)
})

require('@site/src/theme/prism-prisma.js')

// @ts-ignore
delete (globalThis as Optional<typeof globalThis, 'Prism'>).Prism
}
25 changes: 25 additions & 0 deletions src/theme/prism-prisma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Prism.languages.prisma = Prism.languages.extend('clike', {
keyword: /\b(?:datasource|enum|generator|model|type|view)\b/,
'type-class-name': /(\s+)[A-Z]\w+/, ///(\b)(\s+)[A-Z]\w+/
})

Prism.languages.javascript['class-name'][0].pattern =
/(\b(?:model|datasource|enum|generator|type|model|view)\s+)[\w.\\]+/

Prism.languages.insertBefore('prisma', 'function', {
annotation: {
pattern: /(^|[^.])@+\w+/,
lookbehind: true,
alias: 'punctuation',
},
})

Prism.languages.insertBefore('prisma', 'punctuation', {
'type-args': /\b(?:references|fields|onDelete|onUpdate):/,
})

Prism.languages.insertBefore('prisma', 'type-class-name', {
'not-class': /\n(\s+)[A-Z]\w+/,
})

Prism.languages.json5 = Prism.languages.js
6 changes: 6 additions & 0 deletions static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
User-agent: *
Disallow: /
Disallow: /*?query=*
Disallow: /*?page=*
Disallow: /*&query=*
Disallow: /*&page=*

0 comments on commit 166650a

Please sign in to comment.