From a1f33f15718d6a0fb6609f731041354b6d3b7187 Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Fri, 27 Nov 2020 21:48:25 +0800 Subject: [PATCH] feat: automatically detect dark theme --- docs/main.js | 1 - src/docup.ts | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/main.js b/docs/main.js index 90cebaa..6e78027 100644 --- a/docs/main.js +++ b/docs/main.js @@ -5,7 +5,6 @@ init({ logo: '', description: 'Simply beautiful documentation.', highlightLanguages: ['nginx'], - theme: 'dark', props: { langs: process.env.PRISM_LANGUAGES, }, diff --git a/src/docup.ts b/src/docup.ts index 9ee8322..4fe8a1e 100644 --- a/src/docup.ts +++ b/src/docup.ts @@ -33,13 +33,18 @@ export class Docup { options: InstanceOptions constructor(options: Options = {}) { + const matchedDarkTheme = + typeof window !== 'undefined' && + window.matchMedia && + window.matchMedia('(prefers-color-scheme: dark)').matches + this.options = { title: options.title || document.title || 'Docup', indexFile: 'README.md', root: '', base: '/', highlight: true, - theme: 'default', + theme: matchedDarkTheme ? 'dark' : 'default', ...options, } }