From e4c785d8ddb9041cbfb8f6a16c577fc08f9062c6 Mon Sep 17 00:00:00 2001 From: Hatem Hosny Date: Sun, 5 Jan 2025 02:03:11 +0200 Subject: [PATCH] feat: add support for running sass --- source/_posts/sass.md | 1 + themes/coo/layout/_partial/scripts.ejs | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/source/_posts/sass.md b/source/_posts/sass.md index 312c160..2ac1181 100644 --- a/source/_posts/sass.md +++ b/source/_posts/sass.md @@ -11,6 +11,7 @@ intro: | This is a quick reference cheat sheet that lists the most useful features of [SASS](https://sass-lang.com). plugins: - copyCode + - runCode --- ## Sass Basics diff --git a/themes/coo/layout/_partial/scripts.ejs b/themes/coo/layout/_partial/scripts.ejs index 49dcbb9..2342322 100644 --- a/themes/coo/layout/_partial/scripts.ejs +++ b/themes/coo/layout/_partial/scripts.ejs @@ -95,7 +95,11 @@ runButton.addEventListener('click', () => { let content = codeBlock.textContent; let language = [...codeBlock.classList].filter(c => c.startsWith("language-"))[0].replace("language-", ""); - const editorId = ['javascript', 'python'].includes(language) ? 'script' : 'markup'; + const editorId = ['javascript', 'python'].includes(language) + ? 'script' + : ['scss'].includes(language) + ? 'style' + : 'markup'; const title = codeBlock.closest('.h3-wrap')?.querySelector('h3')?.textContent.replace('#', '') || ''; if (language === 'python') { @@ -111,7 +115,7 @@ } } - let config = { + const baseConfig = { title, activeEditor: editorId, [editorId]: { @@ -122,10 +126,11 @@ status: 'open', } } + let config = baseConfig; if (language === 'markdown') { config = { - ...config, + ...baseConfig, style: { language: 'css', content: '@import "github-markdown-css";\n\nbody {\n border: 1px solid #e1e4e8;\n border-radius: 4px;\n padding: 20px;\n margin: 20px !important;\n}\n', @@ -140,6 +145,16 @@ } } + if (language === 'scss') { + config = { + ...baseConfig, + tools: { + status: 'open', + active: 'compiled', + } + } + } + const plaugroundUrl = livecodes.getPlaygroundUrl({config}); window.open(plaugroundUrl, '_blank'); });