Skip to content

Commit

Permalink
Merge branch 'main' into tracing-env-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhghomon authored Jan 3, 2025
2 parents 33bd93b + 98aea8d commit b7e407b
Show file tree
Hide file tree
Showing 130 changed files with 2,998 additions and 221 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ deploy:
@echo "Deploy..."
aws s3 sync --region eu-west-2 --cache-control "public, max-age=31536000, immutable" --exclude '.DS_Store' --exclude '*' --include '*.webp' --content-type 'image/webp' ./dist/docs/_astro s3://www.surrealdb.com/docs/_astro/
aws s3 sync --region eu-west-2 --cache-control "public, max-age=31536000, immutable" --exclude '.DS_Store' --exclude '*.webp' ./dist/docs/_astro s3://www.surrealdb.com/docs/_astro/
aws s3 sync --region eu-west-2 --cache-control "public, max-age=86400" --exclude '.DS_Store' ./dist/docs/~partytown s3://www.surrealdb.com/docs/~partytown/
aws s3 sync --region eu-west-2 --cache-control "public, max-age=30" --delete --exclude '*' --include '*.html' ./dist/docs/ s3://www.surrealdb.com/docs/

.PHONY: stage
stage:
@echo "Stage..."
aws s3 sync --region eu-west-2 --cache-control "public, max-age=31536000, immutable" --exclude '.DS_Store' --exclude '*' --include '*.webp' --content-type 'image/webp' ./dist/docs/_astro s3://www.surrealdb.dev/docs/_astro/
aws s3 sync --region eu-west-2 --cache-control "public, max-age=31536000, immutable" --exclude '.DS_Store' --exclude '*.webp' ./dist/docs/_astro s3://www.surrealdb.dev/docs/_astro/
aws s3 sync --region eu-west-2 --cache-control "public, max-age=86400" --exclude '.DS_Store' ./dist/docs/~partytown s3://www.surrealdb.dev/docs/~partytown/
aws s3 sync --region eu-west-2 --cache-control "public, max-age=30" --delete --exclude '*' --include '*.html' ./dist/docs/ s3://www.surrealdb.dev/docs/
2 changes: 0 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mdx from '@astrojs/mdx';
import partytown from '@astrojs/partytown';
import solidJs from '@astrojs/solid-js';
import tailwind from '@astrojs/tailwind';
import compress from 'astro-compress';
Expand Down Expand Up @@ -32,7 +31,6 @@ export default defineConfig({
tailwind({
nesting: true,
}),
partytown(),
compress({
Image: false,
}),
Expand Down
3 changes: 2 additions & 1 deletion aws/viewer-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ function handler(event) {
case 'surrealql':
case 'sdk':
case 'tutorials':
case 'cloud':
case undefined:
break;
default:
Expand All @@ -256,4 +257,4 @@ function handler(event) {

return request;

}
}
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@astrojs/partytown": "^2.1.2",
"@biomejs/biome": "1.8.3",
"astro-compress": "^2.3.5",
"esbuild": "^0.23.1",
Expand Down
146 changes: 139 additions & 7 deletions scripts/post-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,132 @@ const scripts = [
'https://static.ads-twitter.com/uwt.js',
];

await extractInlineResources();
await checkBrokenLinks();
await fetchRemoteResources();
await extractInlineResources();

async function checkBrokenLinks() {
const broken: string[] = [];
const files = await glob('**/*.html', {
cwd: __dist,
dot: true,
absolute: true,
filesOnly: true,
});

const websiteCache = new Map<string, boolean>();
const self = ['https://surrealdb.com', 'https://www.surrealdb.com'];

for (const file of files) {
let loggedFile = false;
const raw = fs.readFileSync(file, { encoding: 'utf-8' });
const parsed = parseHTML(raw, {
comment: true,
});

const links = parsed.querySelectorAll('a');
for (const link of links) {
let href = link.getAttribute('href');
if (!href) {
continue;
}

let hasIssue = false;
function issue(issue: string) {
if (!href) {
return;
}

if (!broken.includes(href)) {
broken.push(href);
}

if (!hasIssue && !loggedFile) {
console.error(`\n[ERROR] In file: ${file}`);
loggedFile = true;
}

hasIssue = true;
console.error(`[ERROR] ${issue}`);
}

for (const domain of self) {
if (href.startsWith(domain)) {
issue(`External link should be local: ${href}`);
href = href.slice(domain.length);
break;
}
}

if (href.startsWith('/')) {
href = href.split('#')[0];
href = href.split('?')[0];

let exists = false;

switch (true) {
case href === '/docs':
case href.startsWith('/docs/'): {
exists = fs.existsSync(
path.join(__root, 'dist', href, 'index.html')
);
break;
}

default: {
if (!websiteCache.has(href)) {
const res = await fetch(
`https://surrealdb.com${href}`,
{
redirect: 'manual',
}
);
websiteCache.set(href, res.ok);
}

const res = websiteCache.get(href);
if (res === undefined) {
throw new Error(`Cache miss for ${href}`);
}

exists = res;
break;
}
}

if (!exists) {
issue(`Broken link: ${href}`);
}
}

if (hasIssue) {
let elemStr = link.toString();
if (elemStr.length > 100) {
elemStr = `${elemStr.slice(0, 97)}...`;
}

console.error(`[ERROR] For element: ${elemStr}`);
}
}
}

if (broken.length > 0) {
console.error('\n=============================================');
console.error('\n[ERROR] Broken links found.');
console.error(
'[ERROR] Possible issues include dead links, redirected links, or external links that should be local.'
);
console.error('[ERROR] Check the above logs for more in-depth details');
console.error("[ERROR] Here's the list: \n");
for (const link of broken) {
console.error(`[ERROR] Broken link: ${link}`);
}

console.error('\n');

throw new Error('Broken links found');
}
}

async function fetchRemoteResources() {
// Fetch the remote scripts
Expand All @@ -28,12 +152,20 @@ async function fetchRemoteResources() {
fs.writeFileSync(path.join(__astro, name), await minifyJS(content));
// Scan the JS files in the dist folder
console.log('[EXTRACT] Scanning JS files in dist/docs/ folder');
const files = await glob('**/*.js', {
cwd: __dist,
dot: true,
absolute: true,
filesOnly: true,
});
const files = [
...(await glob('**/*.js', {
cwd: __dist,
dot: true,
absolute: true,
filesOnly: true,
})),
...(await glob('**/*.html', {
cwd: __dist,
dot: true,
absolute: true,
filesOnly: true,
})),
];
// Loop over each file and process the content
console.log(`[EXTRACT] Found ${files.length} JS files`);
for (const file of files) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/cloud-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/configure-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/create-instance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/create-root-user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/light/cloud-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/open-in-cli.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/open-in-http.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/open-in-sdk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/open-in-surrealist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/querying-instance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/surreal-sidekick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/surrealcloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/image/cloud/update-billing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions src/components/RenderDoc.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { getEntry } from 'astro:content';
import type { CollectionKey } from 'astro:content';
import { PageHeadings } from '@components/PageHeadings.tsx';
import Sidebar from '@components/Sidebar/index.astro';
import { generateBreadcrumb, generateSidebar } from '@src/util/doc';
import {
findNextPage,
findPreviousPage,
generateBreadcrumb,
generateSidebar,
} from '@src/util/doc';
import { Icon } from 'astro-icon/components';
import BaseLayout from './layout/BaseLayout.astro';
import MarkdownContainer from './shared/MarkdownContainer.astro';
Expand All @@ -31,8 +36,9 @@ if (!entry) {
const { Content, headings } = await entry.render();
const sidebarItems = await generateSidebar(collection);
const sidebarIndex = sidebarItems.flat.findIndex((item) => item.slug === slug);
const prev = sidebarItems.flat.at(sidebarIndex - 1);
const next = sidebarItems.flat.at(sidebarIndex + 1) ?? sidebarItems.flat[0];
const prev = findPreviousPage(sidebarItems.flat, sidebarIndex);
const next =
findNextPage(sidebarItems.flat, sidebarIndex) ?? sidebarItems.flat[0];
function filteredHeadings() {
if (
Expand Down
13 changes: 13 additions & 0 deletions src/components/Sidebar/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import LightSurrealDB from '@img/icon/light/surrealdb.png';
import LightSurrealist from '@img/icon/light/surrealdb.png';
import LightSurrealML from '@img/icon/light/surrealml.png';
import LightSurrealQL from '@img/icon/light/surrealql.png';
import LightCloud from '@img/image/cloud/surrealcloud.png';
import DarkCloud from '@img/image/cloud/surrealcloud.png';

import DarkSurrealDB from '@img/icon/dark/surrealdb.png';
import DarkSurrealist from '@img/icon/dark/surrealist.png';
Expand Down Expand Up @@ -127,6 +129,17 @@ export const metadata = {
href: 'https://github.com/surrealdb/surrealdb',
},
},
'doc-cloud': {
title: 'Surreal Cloud (Beta)',
icon: {
light: LightCloud,
dark: DarkCloud,
},
repo: {
title: 'Forum',
href: '/community',
},
},
'doc-surrealist': {
title: 'Surrealist',
icon: {
Expand Down
18 changes: 0 additions & 18 deletions src/components/layout/Analytics.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@

<script defer is:inline>

// Clarity

window.clarity = function () { (window.clarity.q = window.clarity.q || []).push(arguments) };

{
let s = document.createElement('script');
s.src = 'https://www.clarity.ms/tag/idmjleqtib';
s.async = false;
s.defer = true;
document.head.appendChild(s);
}

</script>

<script defer is:inline type="text/partytown">

// Common Room

window.signals = Object.assign(
Expand Down Expand Up @@ -65,9 +49,7 @@
// Google

window.dataLayer = window.dataLayer || [];

window.gtag = function () { window.dataLayer.push(arguments); };

gtag('js', new Date());
gtag('config', 'G-J1NWM32T1V');

Expand Down
10 changes: 5 additions & 5 deletions src/components/layout/Footer/Footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
Discord
</a>
<span>•</span>
<a href="https://surrealdb.com/community">
<a href="/community">
Community
</a>
<span>•</span>
<a href="https://surrealdb.com/cloud">
<a href="/cloud">
Cloud
</a>
<span>•</span>
<a href="https://surrealdb.com/features">
<a href="/features">
Features
</a>
<span>•</span>
<a href="https://surrealdb.com/releases">
<a href="/releases">
Releases
</a>
<span>•</span>
<a href="https://surrealdb.com/install">
<a href="/install">
Install
</a>
</div>
1 change: 1 addition & 0 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const abstractDoc = defineCollection({

export const docs = [
'surrealdb',
'cloud',
'surrealist',
'surrealml',
'surrealql',
Expand Down
4 changes: 4 additions & 0 deletions src/content/doc-cloud/advanced-topics/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"sidebar_label": "Advanced topics",
"sidebar_position": 5
}
Loading

0 comments on commit b7e407b

Please sign in to comment.