Skip to content

Commit

Permalink
run format on the docs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Jan 31, 2024
1 parent ad6a1b5 commit 6102d13
Show file tree
Hide file tree
Showing 25 changed files with 1,764 additions and 1,817 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
paths:
- docs/**

concurrency:
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

Expand All @@ -23,7 +23,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 16.x

# cache node_modules
- name: Restore cached dependencies
uses: actions/cache@v3
Expand Down
54 changes: 25 additions & 29 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { defineConfig } from 'vitepress'
import KnexDialectsPlugins from './knexDialects'
import { defineConfig } from 'vitepress';
import KnexDialectsPlugins from './knexDialects';

export default defineConfig({
title: 'Knex.js',
description: 'Beta knex.js documentation.',
base: '/',
srcDir: 'src',
head: [
["link", { rel: "icon", type: "image/png", href: "/knex-logo.png" }],
],
head: [['link', { rel: 'icon', type: 'image/png', href: '/knex-logo.png' }]],
themeConfig: {
logo: '/knex-logo.png',
repo: 'knex/knex',
Expand All @@ -27,7 +25,7 @@ export default defineConfig({
{
text: 'Changelog',
link: '/changelog.html',
}
},
],
sidebar: {
'/guide/': getGuideSidebar(),
Expand All @@ -38,72 +36,70 @@ export default defineConfig({
apiKey: '44b5077836c1c8fba0f364383dde7fb4',
indexName: 'knex',
initialQuery: '',
}
},
},
vite: {
plugins: [
KnexDialectsPlugins()
]
}
})
vite: {
plugins: [KnexDialectsPlugins()],
},
});

function getGuideSidebar() {
return [
{
text: 'Installation',
link: '/guide/'
link: '/guide/',
},
{
text: 'Query Builder',
link: '/guide/query-builder'
link: '/guide/query-builder',
},
{
text: 'Transactions',
link: '/guide/transactions'
link: '/guide/transactions',
},
{
text: 'Schema Builder',
link: '/guide/schema-builder'
link: '/guide/schema-builder',
},
{
text: 'Raw',
link: '/guide/raw'
link: '/guide/raw',
},
{
text: 'Ref',
link: '/guide/ref'
link: '/guide/ref',
},
{
text: 'Utility',
link: '/guide/utility'
link: '/guide/utility',
},
{
text: 'Interfaces',
link: '/guide/interfaces'
link: '/guide/interfaces',
},
{
text: 'Migrations',
link: '/guide/migrations'
link: '/guide/migrations',
},
{
text: 'Extending',
link: '/guide/extending'
}
]
link: '/guide/extending',
},
];
}
function getFaqSidebar() {
return [
{
text: 'F.A.Q.',
link: '/faq/'
link: '/faq/',
},
{
text: 'Recipes',
link: '/faq/recipes'
link: '/faq/recipes',
},
{
text: 'Support',
link: '/faq/support'
link: '/faq/support',
},
]
];
}
35 changes: 17 additions & 18 deletions docs/.vitepress/knexDialects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import Knex from 'knex'
import type { PluginOption } from 'vite'
import Knex from 'knex';
import type { PluginOption } from 'vite';

const dialects = {
'better-sqlite3': Knex({ client: 'better-sqlite3' }),
Expand All @@ -13,35 +12,35 @@ const dialects = {
postgres: Knex({ client: 'postgres' }),
redshift: Knex({ client: 'redshift' }),
sqlite3: Knex({ client: 'sqlite3' }),
}
};

export default function knexDialects (): PluginOption {
const regex = /<SqlOutput[\s]*code="([^"]+)"[\s]*\/>/ig
export default function knexDialects(): PluginOption {
const regex = /<SqlOutput[\s]*code="([^"]+)"[\s]*\/>/gi;

return {
name: 'transform-file',
enforce: 'pre',

transform(src, id) {
if (id.endsWith('.md')) {
const matches = src.matchAll(regex)
const matches = src.matchAll(regex);
for (const match of matches) {
let markdown = ''
const getCode = Function("knex", `return knex.raw(${match[1]});`);
let markdown = '';
const getCode = Function('knex', `return knex.raw(${match[1]});`);

for (const dialect in dialects) {
const knex = dialects[dialect]
const { sql } = getCode(knex)
const output = sql.toString()
const knex = dialects[dialect];
const { sql } = getCode(knex);
const output = sql.toString();

markdown += `<div data-dialect="${dialect}">\n\n\`\`\`sql\n${output}\n\`\`\`\n\n</div>\n`
markdown += `<div data-dialect="${dialect}">\n\n\`\`\`sql\n${output}\n\`\`\`\n\n</div>\n`;
}

src = src.replace(match[0], markdown)
src = src.replace(match[0], markdown);
}
}

return src
}
}
}
return src;
},
};
}

0 comments on commit 6102d13

Please sign in to comment.