-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
177 changed files
with
7,738 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: codeql | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
analyze: | ||
name: analyze | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ 'javascript' ] | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
- name: initialize codeql | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
languages: ${{ matrix.language }} | ||
- name: build | ||
run: | | ||
npm install | ||
bash scripts/build.sh | ||
- name: analyze | ||
uses: github/codeql-action/analyze@v2 |
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,26 @@ | ||
name: cover | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
cover: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
- name: cover | ||
run: | | ||
npm install | ||
npm run cover | ||
- name: upload report | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
fail_ci_if_error: true | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
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,27 @@ | ||
name: publish | ||
on: | ||
workflow_dispatch: { } | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pages: write | ||
id-token: write | ||
environment: | ||
name: github-pages | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v3 | ||
- name: build | ||
run: | | ||
cd docs | ||
npm install | ||
npm run build | ||
- uses: actions/configure-pages@v3 | ||
- uses: actions/upload-pages-artifact@v2 | ||
with: | ||
path: .vitepress/dist | ||
- uses: actions/deploy-pages@v2 |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: publish | ||
|
||
on: | ||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
- name: setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
registry-url: "https://npm.pkg.github.com" | ||
- name: build | ||
run: | | ||
npm install | ||
bash scripts/build.sh | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.GH_KEY }} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
cache |
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,76 @@ | ||
import { defineConfig } from "vitepress"; | ||
import md from "./md"; | ||
import escapeCode from "./escape-code"; | ||
import imgit from "imgit/vite"; | ||
import svg from "imgit/svg"; | ||
import youtube from "imgit/youtube"; | ||
|
||
// https://vitepress.dev/reference/site-config | ||
export default defineConfig({ | ||
title: "imgit", | ||
titleTemplate: ":title • imgit", | ||
appearance: "dark", | ||
cleanUrls: true, | ||
lastUpdated: true, | ||
markdown: md, | ||
vite: { plugins: [imgit({ width: 688, plugins: [svg(), youtube(), escapeCode] })] }, | ||
head: [ | ||
["link", { rel: "icon", href: "/favicon.svg" }], | ||
["link", { rel: "preload", href: "/fonts/inter.woff2", as: "font", type: "font/woff2", crossorigin: "" }], | ||
["link", { rel: "preload", href: "/fonts/jb.woff2", as: "font", type: "font/woff2", crossorigin: "" }], | ||
["meta", { name: "theme-color", content: "#ee3248" }], | ||
["meta", { name: "og:image", content: "/img/og.jpg" }], | ||
["meta", { name: "twitter:card", content: "summary_large_image" }] | ||
], | ||
themeConfig: { | ||
logo: { src: "/favicon.svg" }, | ||
logoLink: "/", | ||
socialLinks: [{ icon: "github", link: "https://github.com/elringus/imgit" }], | ||
search: { provider: "local" }, | ||
lastUpdated: { text: "Updated", formatOptions: { dateStyle: "medium" } }, | ||
sidebarMenuLabel: "Menu", | ||
darkModeSwitchLabel: "Appearance", | ||
returnToTopLabel: "Return to top", | ||
outline: { label: "On this page", level: "deep" }, | ||
docFooter: { prev: "Previous page", next: "Next page" }, | ||
nav: [ | ||
{ text: "Guide", link: "/guide/", activeMatch: "/guide/" }, | ||
{ | ||
text: `v${(await import("./../../package.json")).version}`, items: [ | ||
{ text: "Changes", link: "https://github.com/elringus/imgit/releases/latest" }, | ||
{ text: "Contribute", link: "https://github.com/elringus/imgit/labels/help%20wanted" } | ||
] | ||
} | ||
], | ||
editLink: { | ||
pattern: "https://github.com/elringus/imgit/edit/main/docs/:path", | ||
text: "Edit this page on GitHub" | ||
}, | ||
sidebar: { | ||
"/guide/": [ | ||
{ | ||
text: "Guide", | ||
items: [ | ||
{ text: "Introduction", link: "/guide/" }, | ||
{ text: "Getting Started", link: "/guide/getting-started" }, | ||
{ text: "GPU Acceleration", link: "/guide/gpu-acceleration" }, | ||
{ text: "Plugins", link: "/guide/plugins" } | ||
] | ||
}, | ||
{ | ||
text: "Integrations", | ||
items: [ | ||
{ text: "Vite", link: "/guide/integrations/vite" }, | ||
{ text: "Astro", link: "/guide/integrations/astro" }, | ||
{ text: "Nuxt", link: "/guide/integrations/nuxt" }, | ||
{ text: "Remix", link: "/guide/integrations/remix" }, | ||
{ text: "SolidStart", link: "/guide/integrations/solid" }, | ||
{ text: "SvelteKit", link: "/guide/integrations/svelte" }, | ||
{ text: "VitePress", link: "/guide/integrations/vitepress" } | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
sitemap: { hostname: "https://imgit.dev" } | ||
}); |
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,50 @@ | ||
import { Plugin, CapturedAsset, stages } from "imgit/server"; | ||
|
||
type Range = { start: number; end: number; }; | ||
|
||
export default { capture } satisfies Plugin; | ||
|
||
// Remove captures inside Markdown code blocks (```code```). | ||
function capture(content: string, assets: CapturedAsset[]): boolean { | ||
stages.capture.capture(content, assets); | ||
if (assets.length === 0) return true; | ||
const ranges = findCodeRanges(content); | ||
if (ranges.length > 0) | ||
assets.splice(0, assets.length, ...assets.filter(a => !isInCodeBlock(a, ranges))); | ||
return true; | ||
} | ||
|
||
function findCodeRanges(content: string): Range[] { | ||
const ranges = new Array<Range>(); | ||
let tickCount = 0; | ||
let openIndex = -1; | ||
for (let i = 0; i < content.length; i++) | ||
if (content[i] === "`") handleTick(i); | ||
else tickCount = 0; | ||
return ranges; | ||
|
||
function handleTick(index: number): void { | ||
if (++tickCount < 3) return; | ||
if (openIndex === -1) openRange(index); | ||
else closeRange(index); | ||
} | ||
|
||
function openRange(index: number): void { | ||
openIndex = index; | ||
tickCount = 0; | ||
} | ||
|
||
function closeRange(index: number): void { | ||
ranges.push({ start: openIndex, end: index }); | ||
openIndex = -1; | ||
tickCount = 0; | ||
} | ||
} | ||
|
||
function isInCodeBlock(asset: CapturedAsset, ranges: Range[]): boolean { | ||
for (const range of ranges) | ||
if (asset.syntax.index >= range.start && | ||
(asset.syntax.index + asset.syntax.text.length) <= range.end) | ||
return true; | ||
return false; | ||
} |
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,11 @@ | ||
import { MarkdownOptions, MarkdownRenderer } from "vitepress"; | ||
import { AppendIconToExternalLinks } from "./md-link"; | ||
|
||
export default { | ||
config: installPlugins, | ||
attrs: { disable: true } // https://github.com/vuejs/vitepress/issues/2440 | ||
} satisfies MarkdownOptions; | ||
|
||
function installPlugins(md: MarkdownRenderer) { | ||
md.use(AppendIconToExternalLinks); | ||
} |
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,30 @@ | ||
import type { MarkdownRenderer } from "vitepress"; | ||
import type { RenderRule } from "markdown-it/lib/renderer"; | ||
|
||
export function AppendIconToExternalLinks(md: MarkdownRenderer) { | ||
const renderToken: RenderRule = (tokens, idx, options, env, self) => self.renderToken(tokens, idx, options); | ||
const defaultLinkOpenRenderer = md.renderer.rules.link_open || renderToken; | ||
const defaultLinkCloseRenderer = md.renderer.rules.link_close || renderToken; | ||
let externalLinkOpen = false; | ||
|
||
md.renderer.rules.link_open = (tokens, idx, options, env, self) => { | ||
const token = tokens[idx]; | ||
const href = token.attrGet("href"); | ||
|
||
if (href) { | ||
token.attrJoin("class", "vp-link"); | ||
if (/^((ht|f)tps?):\/\/?/.test(href)) | ||
externalLinkOpen = true; | ||
} | ||
|
||
return defaultLinkOpenRenderer(tokens, idx, options, env, self); | ||
}; | ||
|
||
md.renderer.rules.link_close = (tokens, idx, options, env, self) => { | ||
if (externalLinkOpen) { | ||
externalLinkOpen = false; | ||
return `<span class="external-link-icon"> ↗</span>${self.renderToken(tokens, idx, options)}`; | ||
} | ||
return defaultLinkCloseRenderer(tokens, idx, options, env, self); | ||
}; | ||
} |
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,39 @@ | ||
// Based on https://github.com/rlidwka/markdown-it-regexp. | ||
|
||
import { inherits } from "node:util"; | ||
import { MarkdownEnv, MarkdownRenderer } from "vitepress"; | ||
|
||
let instanceId = 0; | ||
|
||
export function Replacer(regexp: RegExp, replace: (match: string[], env: MarkdownEnv) => string) { | ||
let self: any = (md: any) => self.init(md); | ||
self.__proto__ = Replacer.prototype; | ||
self.regexp = new RegExp("^" + regexp.source, regexp.flags); | ||
self.replace = replace; | ||
self.id = `md-replacer-${instanceId}`; | ||
instanceId++; | ||
return self; | ||
} | ||
|
||
inherits(Replacer, Function); | ||
|
||
Replacer.prototype.init = function (md: MarkdownRenderer) { | ||
md.inline.ruler.push(this.id, this.parse.bind(this)); | ||
md.renderer.rules[this.id] = this.render.bind(this); | ||
}; | ||
|
||
Replacer.prototype.parse = function (state: any, silent: any) { | ||
let match = this.regexp.exec(state.src.slice(state.pos)); | ||
if (!match) return false; | ||
|
||
state.pos += match[0].length; | ||
if (silent) return true; | ||
|
||
let token = state.push(this.id, "", 0); | ||
token.meta = { match: match }; | ||
return true; | ||
}; | ||
|
||
Replacer.prototype.render = function (tokens: any, id: any, options: any, env: MarkdownEnv) { | ||
return this.replace(tokens[id].meta.match, env); | ||
}; |
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,12 @@ | ||
import DefaultTheme from "vitepress/theme-without-fonts"; | ||
import "./style.css"; | ||
|
||
// Have to import client assets manually due to vitepress | ||
// bug: https://github.com/vuejs/vitepress/issues/3314 | ||
import "imgit/styles"; | ||
import "imgit/styles/youtube"; | ||
import "imgit/client"; | ||
import "imgit/client/youtube"; | ||
|
||
// https://vitepress.dev/guide/extending-default-theme | ||
export default { extends: { Layout: DefaultTheme.Layout } }; |
Oops, something went wrong.