Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions demo/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@

Route::passkeys();

Route::get('/', function () {
return redirect('/docs/index.html');
});
Route::redirect('/', '/docs');

Route::get('/docs{segment}', function (?string $segment = null) {
$segment = trim($segment ?: '', '/');

if (! str_contains($segment, '/')) {
$versions = json_decode(file_get_contents(base_path('../docs/versions/config.json')), true);
if ($segment !== $versions[0]['slug']) {
return redirect('/docs/'.$versions[0]['slug']);
}
}

return match (true) {
file_exists($html = public_path('/docs/'.$segment.'.html')) => response()->file($html),
file_exists($html = public_path('/docs/'.$segment.'/index.html')) => response()->file($html),
default => abort(404),
};
})->where('segment', '.*');

Route::get('/post/{post}', function (Post $post) {
return view('pages.post', ['post' => $post]);
Expand Down
199 changes: 101 additions & 98 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,119 +1,122 @@
import { type DefaultTheme, defineConfig, loadEnv } from 'vitepress'
import * as path from "path";
import { sidebar } from "./sidebar";
import { transformContent } from "./transform-content";
import versions from '../versions/config.json';
import { sidebar } from "./sidebar";

const env = loadEnv('', path.resolve(__dirname, '../../demo'), ['APP', 'DOCS']);

const {
APP_URL = 'https://sharp.code16.fr',
DOCS_TITLE = 'Sharp',
DOCS_ENABLE_VERSIONING = 'false',
DOCS_VERSION = '7.0',
DOCS_VERSION_ITEMS = '[]',
DOCS_MAIN_URL = APP_URL,
DOCS_ALGOLIA_TAG = 'v7'
} = env;

const isLastVersion = DOCS_MAIN_URL === APP_URL;
const DOCS_HOME_URL = isLastVersion ? '/docs/' : DOCS_MAIN_URL;

export default defineConfig({
lang: 'en-US',
title: DOCS_TITLE,
description: 'The Content Management Framework for Laravel.',
base: '/docs/',

lastUpdated: true,
cleanUrls: true,

head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/docs/favicon.svg' }],
['link', { rel: 'icon', type: 'image/png', href: '/docs/favicon.png' }],
['meta', { name: 'theme-color', content: '#007bff' }],
['meta', { name: 'og:type', content: 'website' }],
['meta', { name: 'og:locale', content: 'en' }],
['meta', { name: 'og:site_name', content: DOCS_TITLE }],
['meta', { name: 'og:image', content: `${APP_URL}/og-image.png` }],
['script', { src: 'https://cdn.usefathom.com/script.js', 'data-site': 'EELMENOG', 'data-spa': 'auto', defer: '' }]
],

markdown: {
config(md) {
const render = md.render;
md.render = (...args) => {
return transformContent(render.call(md, ...args));
}
},
},

themeConfig: {
logo: { src: '/logo.svg', width: 100, height: 24, alt: DOCS_TITLE },

logoLink: DOCS_HOME_URL,

siteTitle: false,

nav: nav(),

outline: {
level: [2, 3],
},

sidebar: {
'/guide/': sidebar()
},

editLink: isLastVersion ? {
pattern: 'https://github.com/code16/sharp/edit/main/docs/:path',
text: 'Edit this page on GitHub'
} : undefined,

socialLinks: [
{ icon: 'github', link: 'https://github.com/code16/sharp' },
{ icon: 'discord', link: 'https://discord.com/invite/sFBT5c3XZz' },
export default async () => {
const version = process.env.VERSION
? versions.find(v => v.slug === process.env.VERSION)!
: versions[0];

return defineConfig({
lang: 'en-US',
title: version.title,
description: 'The Content Management Framework for Laravel.',
base: process.env.VERSION ? '/docs/'+version.slug : '/docs/',
srcDir: process.env.VERSION ? path.resolve(__dirname, '../versions/'+version.slug) : process.cwd(),
outDir: path.resolve(__dirname, './dist/'+version.slug),

lastUpdated: true,
cleanUrls: true,

head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/docs/favicon.svg' }],
['link', { rel: 'icon', type: 'image/png', href: '/docs/favicon.png' }],
['meta', { name: 'theme-color', content: '#007bff' }],
['meta', { name: 'og:type', content: 'website' }],
['meta', { name: 'og:locale', content: 'en' }],
['meta', { name: 'og:site_name', content: version.title! }],
['meta', { name: 'og:image', content: `${APP_URL}/og-image.png` }],
['script', { src: 'https://cdn.usefathom.com/script.js', 'data-site': 'EELMENOG', 'data-spa': 'auto', defer: '' }]
],

footer: {
message: 'Released under the MIT License.',
copyright: 'Copyright © 2017-present Code16'
markdown: {
config(md) {
const render = md.render;
md.render = (...args) => {
return transformContent(render.call(md, ...args));
}
},
},

search: {
provider: 'algolia',
options: {
appId: '1A1N8XRQFM',
apiKey: 'c5c8c8034f3c0586d562fdbb0a4d26cb',
indexName: 'code16_sharp',
searchParameters: {
facetFilters: [`tags:${DOCS_ALGOLIA_TAG}`],
},
}
themeConfig: {
logo: { src: '/logo.svg', width: 100, height: 24, alt: version.title },

logoLink: APP_URL,

siteTitle: false,

nav: nav(),

outline: {
level: [2, 3],
},

sidebar: {
'/guide/': process.env.VERSION
? (await import(`../versions/${version.slug}/.vitepress/sidebar.ts`)).sidebar()
: sidebar()
},

editLink: {
pattern: `https://github.com/code16/sharp/edit/${version.branch}/docs/:path`,
text: 'Edit this page on GitHub'
},

socialLinks: [
{ icon: 'github', link: 'https://github.com/code16/sharp' },
{ icon: 'discord', link: 'https://discord.com/invite/sFBT5c3XZz' },
],

footer: {
message: 'Released under the MIT License.',
copyright: 'Copyright © 2017-present Code16'
},

search: {
provider: 'algolia',
options: {
appId: '1A1N8XRQFM',
apiKey: 'c5c8c8034f3c0586d562fdbb0a4d26cb',
indexName: 'code16_sharp',
searchParameters: {
facetFilters: [`tags:${version.algoliaTag}`],
},
}
},
},
},
});
});


function nav(): DefaultTheme.NavItem[] {
return [
{ text: 'Documentation', link: '/guide/' },
...DOCS_ENABLE_VERSIONING === 'true' ? [
function nav(): DefaultTheme.NavItem[] {
return [
{ text: 'Documentation', link: '/guide/' },
{
text: DOCS_VERSION,
items: JSON.parse(DOCS_VERSION_ITEMS || '[]')
.map(item => ({
text: item.text,
link: item.link,
text: version.name,
items: versions
.map(version => ({
text: version.name,
link: version.url ?? `${APP_URL}/docs/${version.slug}/guide/`,
target: '_self',
})),
}
] : [],
{
text: 'More',
items: [
{ text: 'Demo', link: `${DOCS_MAIN_URL}/sharp/` },
{ text: 'Code 16’s blog', link:'https://code16.fr/blog' },
]
},
];
},
{
text: 'More',
items: [
{ text: 'Demo', link: `${APP_URL}/sharp/` },
{ text: 'Code 16’s blog', link:'https://code16.fr/blog' },
]
},
];
}
}



Loading
Loading