-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate from astro to svelte + vite to improve performance (#…
…131) * add highlighter * add playground url * add markdown support and notification center * fix multiple md files * add meta description with framework list * fix: framework id loop index * store frameworkIdsSelected in locale storage * add generateFrameworkContent vite plugin * add missing snippet case * add content generate cache * add angular component highlighter * improve content generator organization * add format and linter * add git hooks * add default frameworks
- Loading branch information
Showing
63 changed files
with
4,410 additions
and
3,839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
new-section | ||
.eslintcache | ||
yarn.lock | ||
package-lock.json | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
.history | ||
.chrome | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
src/generatedContent |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,8 @@ | ||
{ | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"eslint.probe": ["javascript", "javascriptreact", "vue"], | ||
"editor.formatOnSave": false, | ||
// Runs Prettier, then ESLint | ||
"editor.codeActionsOnSave": ["source.formatDocument", "source.fixAll.eslint"], | ||
"[svelte]": { | ||
"editor.defaultFormatter": "svelte.svelte-vscode" | ||
}, | ||
"cSpell.words": [ | ||
"alpinejs", | ||
"astro", | ||
"astrojs", | ||
"matschik", | ||
"mdast", | ||
"pnpm", | ||
"qwik", | ||
"shiki", | ||
"webp" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import fs from "fs"; | ||
import generateContent from "./lib/generateContent.js"; | ||
import { createFsCache } from "micache"; | ||
import { hashElement } from "folder-hash"; | ||
|
||
const contentDirFsCache = await createFsCache("pluginGenerateFrameworkContent"); | ||
|
||
export default function pluginGenerateFrameworkContent() { | ||
const name = "generateFrameworkContent"; | ||
|
||
function logInfo(...args) { | ||
console.info(`[${name}]`, ...args); | ||
} | ||
|
||
async function build() { | ||
logInfo("Generating framework content files..."); | ||
const contentDirHash = | ||
(await hashElement("content")).hash + (await hashElement("build")).hash; | ||
const contentDirLastHash = await contentDirFsCache.get("contentDirHash"); | ||
if (contentDirHash !== contentDirLastHash) { | ||
await generateContent(); | ||
await contentDirFsCache.set("contentDirHash", contentDirHash); | ||
logInfo(`done`); | ||
} else { | ||
logInfo(`done with cache`); | ||
} | ||
} | ||
|
||
let fsContentWatcher; | ||
if (process.env.NODE_ENV === "development") { | ||
fsContentWatcher = fs.watch("content", { recursive: true }, build); | ||
} | ||
|
||
return { | ||
name, | ||
async buildStart() { | ||
await build(); | ||
}, | ||
buildEnd() { | ||
fsContentWatcher && fsContentWatcher.close(); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
export function mustUseAngularHighlighter(fileContent) { | ||
return ( | ||
fileContent.includes("@angular/core") && fileContent.includes("template") | ||
); | ||
} | ||
|
||
export function highlightAngularComponent(highlighter, fileContent, fileExt) { | ||
const templateCode = getAngularTemplateCode(fileContent); | ||
|
||
let codeHighlighted = ""; | ||
if (templateCode) { | ||
const componentWithEmptyTemplate = | ||
removeAngularTemplateContent(fileContent); | ||
const templateCodeHighlighted = highlighter(templateCode, { | ||
lang: "html", | ||
}); | ||
|
||
const componentWithoutTemplateHighlighted = highlighter( | ||
componentWithEmptyTemplate, | ||
{ | ||
lang: fileExt, | ||
} | ||
); | ||
|
||
codeHighlighted = componentWithoutTemplateHighlighted.replace( | ||
"template", | ||
"template: `" + removeCodeWrapper(templateCodeHighlighted) + "`," | ||
); | ||
} else { | ||
codeHighlighted = highlighter(fileContent, { | ||
lang: fileExt, | ||
}); | ||
} | ||
|
||
return codeHighlighted; | ||
} | ||
|
||
function getAngularTemplateCode(fileContent) { | ||
// regex to grab what is inside angular component template inside backticks | ||
const regex = /template:\s*`([\s\S]*?)`/gm; | ||
|
||
// grab the template string | ||
const template = regex.exec(fileContent); | ||
|
||
if (template) return template[1]; | ||
|
||
return ""; | ||
} | ||
|
||
function removeAngularTemplateContent(fileContent) { | ||
const componentWithoutContentInsideTemplate = fileContent.replace( | ||
/template:\s*`([\s\S]*?)([^*])`,?/gm, | ||
"template" | ||
); | ||
|
||
return componentWithoutContentInsideTemplate; | ||
} | ||
|
||
function removeCodeWrapper(html) { | ||
const regexForWrapper = /<pre([\s\S]*?)><code>([\s\S]*?)<\/code><\/pre>/gm; | ||
const code = regexForWrapper.exec(html); | ||
return code[2]; | ||
} |
Oops, something went wrong.