Skip to content

Commit

Permalink
Merge branch 'micha/astro' of github.com:surrealdb/docs.surrealdb.com…
Browse files Browse the repository at this point in the history
… into micha/astro
  • Loading branch information
Ekwuno committed Sep 17, 2024
2 parents c2a5b8b + 7eef981 commit b457b8a
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 8 deletions.
22 changes: 22 additions & 0 deletions aws/viewer-request/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright © 2024 SurrealDB Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

.PHONY: default
default:
@echo "Choose a Makefile target:"
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print " - " $$1}}' | sort

.PHONY: deploy
deploy:
./deploy.sh
8 changes: 8 additions & 0 deletions aws/viewer-request/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh -x

aws --profile surreal cloudfront describe-function --name www-surrealdb-com-docs-viewer-request > temp.json
ETAG=$(jq -r '.ETag' temp.json)
aws --profile surreal cloudfront update-function --name www-surrealdb-com-docs-viewer-request --function-code fileb://index.js --function-config Comment="",Runtime="cloudfront-js-2.0" --if-match $ETAG > temp.json
ETAG=$(jq -r '.ETag' temp.json)
aws --profile surreal cloudfront publish-function --name www-surrealdb-com-docs-viewer-request --if-match $ETAG > temp.json
rm -rf temp.json
239 changes: 239 additions & 0 deletions aws/viewer-request/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
function redirect(location) {
return {
statusCode: 301,
statusDescription: 'Moved Permanently',
headers: {
'cache-control': {
value: 'public, max-age=86400',
},
location: {
value: location,
},
},
};
}

function handler(event) {

const request = event.request;
const host = request.headers.host.value;
const path = request.uri.toLowerCase();

// Only use the base domain, not subdomains
if (host !== 'surrealdb.com') {
return redirect(`https://surrealdb.com${path}`);
}

// Docusaurus base path always has a trailing slash
if (path === '/docs') {
return redirect('https://surrealdb.com/docs/');
}

// Display the content for the documentation path
if (path === '/docs/') {
request.uri = request.uri.concat('index.html');
return request;
}

// Display any documentation assets and image files
if (path.startsWith('/docs/_astro/') || path.startsWith('/docs/~partytown/')) {
return request;
}

// Redirect any paths which have trailing slashes
if (request.uri.endsWith('/')) {
return redirect(`https://surrealdb.com${path.slice(0, -1)}`);
}

// Redirect any capitalised paths to lowercase
if (path !== request.uri) {
return redirect(`https://surrealdb.com${path}`);
}

if (path.endsWith('/')) {
path = path.slice(0, -1);
}

switch (path) {
// Redirect old sdk libraries page
case '/docs/integration/libraries':
return redirect('https://surrealdb.com/docs/surrealdb/integration/sdks');
// Redirect old websocket protocol page
case '/docs/integration/websocket/text':
case '/docs/integration/websocket/binary':
case '/docs/surrealdb/integration/websocket':
return redirect('https://surrealdb.com/docs/surrealdb/integration/rpc');
// Redirect old DEFINE LOGIN statement page
case '/docs/surrealql/statements/define/login':
return redirect('https://surrealdb.com/docs/surrealdb/surrealql/statements/define/user');
// Redirect NodeJS docs to JavaScript docs
case '/docs/integration/libraries/nodejs':
case '/docs/surrealdb/integration/sdks/nodejs':
return redirect('https://surrealdb.com/docs/sdk/javascript');
// Redirect Deno docs to JavaScript docs
case '/docs/integration/libraries/deno':
case '/docs/surrealdb/integration/sdks/deno':
return redirect('https://surrealdb.com/docs/sdk/javascript');
// Redirect old SurrealQL functions pages
case '/docs/surrealdb/surrealql/functions/array':
case '/docs/surrealdb/surrealql/functions/count':
case '/docs/surrealdb/surrealql/functions/crypto':
case '/docs/surrealdb/surrealql/functions/duration':
case '/docs/surrealdb/surrealql/functions/encoding':
case '/docs/surrealdb/surrealql/functions/geo':
case '/docs/surrealdb/surrealql/functions/http':
case '/docs/surrealdb/surrealql/functions/math':
case '/docs/surrealdb/surrealql/functions/meta':
case '/docs/surrealdb/surrealql/functions/object':
case '/docs/surrealdb/surrealql/functions/parse':
case '/docs/surrealdb/surrealql/functions/rand':
case '/docs/surrealdb/surrealql/functions/search':
case '/docs/surrealdb/surrealql/functions/session':
case '/docs/surrealdb/surrealql/functions/sleep':
case '/docs/surrealdb/surrealql/functions/string':
case '/docs/surrealdb/surrealql/functions/time':
case '/docs/surrealdb/surrealql/functions/type':
case '/docs/surrealdb/surrealql/functions/vector':
return redirect(`https://surrealdb.com/docs/surrealdb/surrealql/functions/database/${path.slice(36)}`);
// Redirect old directory structure
case '/docs/intro':
case '/docs/surrealdb/intro':
return redirect('https://surrealdb.com/docs/surrealdb');
case '/docs/cli/overview':
case '/docs/surrealdb/cli/overview':
return redirect('https://surrealdb.com/docs/surrealdb/cli');
case '/docs/deployment/overview':
case '/docs/surrealdb/deployment/overview':
return redirect('https://surrealdb.com/docs/surrealdb/deployment');
case '/docs/embedding/overview':
case '/docs/surrealdb/embedding/overview':
return redirect('https://surrealdb.com/docs/surrealdb/embedding');
case '/docs/faqs/overview':
case '/docs/surrealdb/faqs/overview':
return redirect('https://surrealdb.com/docs/surrealdb/faqs');
case '/docs/how-to/overview':
case '/docs/surrealdb/how-to/overview':
return redirect('https://surrealdb.com/docs/surrealdb/tutorials');
case '/docs/tutorials/overview':
case '/docs/surrealdb/tutorials/overview':
return redirect('https://surrealdb.com/docs/surrealdb/tutorials');
case '/docs/installation/overview':
case '/docs/surrealdb/installation/overview':
return redirect('https://surrealdb.com/docs/surrealdb/installation');
case '/docs/integration/overview':
case '/docs/surrealdb/integration/overview':
return redirect('https://surrealdb.com/docs/surrealdb/integration');
case '/docs/integration/sdks/overview':
case '/docs/surrealdb/integration/sdks/overview':
return redirect('https://surrealdb.com/docs/surrealdb/integration/sdks');
case '/docs/introduction/overview':
case '/docs/surrealdb/introduction/overview':
return redirect('https://surrealdb.com/docs/surrealdb/introduction');
case '/docs/surrealql/overview':
case '/docs/surrealdb/surrealql/overview':
return redirect('https://surrealdb.com/docs/surrealdb/surrealql');
case '/docs/surrealql/datamodel/overview':
case '/docs/surrealdb/surrealql/datamodel/overview':
return redirect('https://surrealdb.com/docs/surrealdb/surrealql/datamodel');
case '/docs/surrealql/functions/overview':
case '/docs/surrealdb/surrealql/functions/overview':
return redirect('https://surrealdb.com/docs/surrealdb/surrealql/functions');
case '/docs/surrealql/functions/script/overview':
case '/docs/surrealdb/surrealql/functions/script/overview':
return redirect('https://surrealdb.com/docs/surrealdb/surrealql/functions/script');
case '/docs/surrealql/statements/overview':
case '/docs/surrealdb/surrealql/statements/overview':
return redirect('https://surrealdb.com/docs/surrealdb/surrealql/statements');
case '/docs/surrealdb/surrealql':
return redirect('https://surrealdb.com/docs/surrealql');
case '/docs/surrealql/statements/define/overview':
case '/docs/surrealdb/surrealql/statements/define/overview':
return redirect('https://surrealdb.com/docs/surrealdb/surrealql/statements/define');
case '/docs/surrealql/statements/remove/overview':
case '/docs/surrealdb/surrealql/statements/remove/overview':
return redirect('https://surrealdb.com/docs/surrealdb/surrealql/statements/remove');
case '/docs/1.0.x':
case '/docs/1.0.0':
case '/docs/1.1.x':
case '/docs/1.1.0':
case '/docs/1.2.x':
case '/docs/1.2.0':
case '/docs/1.3.x':
case '/docs/1.3.0':
case '/docs/surrealdb/2.x':
case '/docs/surrealdb/1.0.x':
case '/docs/surrealdb/1.0.0':
case '/docs/surrealdb/1.1.x':
case '/docs/surrealdb/1.1.0':
case '/docs/surrealdb/1.2.x':
case '/docs/surrealdb/1.2.0':
case '/docs/surrealdb/1.3.x':
case '/docs/surrealdb/1.3.0':
return redirect('https://surrealdb.com/docs/surrealdb');
}

switch (true) {
// Redirect nightly pages to default
case path.startsWith('/docs/nightly/'):
return redirect(`https://surrealdb.com/docs/surrealdb/${path.slice(14)}`);
// Redirect nightly pages to default
case path.startsWith('/docs/surrealdb/nightly/'):
return redirect(`https://surrealdb.com/docs/surrealdb/${path.slice(24)}`);
// Redirect versioned pages to default
case path.startsWith('/docs/1.0.x/'):
case path.startsWith('/docs/1.0.0/'):
case path.startsWith('/docs/1.1.x/'):
case path.startsWith('/docs/1.1.0/'):
case path.startsWith('/docs/1.2.x/'):
case path.startsWith('/docs/1.2.0/'):
case path.startsWith('/docs/1.3.x/'):
case path.startsWith('/docs/1.3.0/'):
return redirect(`https://surrealdb.com/docs/surrealdb/${path.slice(12)}`);
// Redirect versioned pages to default
case path.startsWith('/docs/surrealdb/2.x/'):
return redirect(`https://surrealdb.com/docs/surrealdb/${path.slice(20)}`);
case path.startsWith('/docs/surrealdb/1.0.x/'):
case path.startsWith('/docs/surrealdb/1.0.0/'):
case path.startsWith('/docs/surrealdb/1.1.x/'):
case path.startsWith('/docs/surrealdb/1.1.0/'):
case path.startsWith('/docs/surrealdb/1.2.x/'):
case path.startsWith('/docs/surrealdb/1.2.0/'):
case path.startsWith('/docs/surrealdb/1.3.x/'):
case path.startsWith('/docs/surrealdb/1.3.0/'):
return redirect(`https://surrealdb.com/docs/surrealdb/${path.slice(22)}`);
// Redirect libraries pages to sdks
case path.startsWith('/docs/integration/libraries/'):
return redirect(`https://surrealdb.com/docs/sdk/${path.slice(28)}`);
case path.startsWith('/docs/surrealdb/integration/sdks/'):
return redirect(`https://surrealdb.com/docs/sdk/${path.slice(33)}`);
// Redirect how-to pages to tutorials
case path.startsWith('/docs/how-to/'):
return redirect(`https://surrealdb.com/docs/surrealdb/tutorials/${path.slice(13)}`);
case path.startsWith('/docs/surrealdb/how-to/'):
return redirect(`https://surrealdb.com/docs/surrealdb/tutorials/${path.slice(23)}`);
// Redirect SurrealQL subpaths to Querying
case path.startsWith('/docs/surrealdb/surrealql/'):
return redirect(`https://surrealdb.com/docs/surrealql/${path.slice(26)}`);
// Redirect all other docs pages
case path.startsWith('/docs/'): {
const splitted = path.split('/').slice(1);
switch (splitted[1]) {
case 'surrealdb':
case 'surrealml':
case 'surrealist':
case 'surrealism':
case 'surrealql':
case 'sdk':
case undefined:
break;
default:
return redirect(`https://surrealdb.com/docs/surrealdb/${path.slice(6)}`);
}
}
}

request.uri = request.uri.concat('.html');

return request;

}
4 changes: 2 additions & 2 deletions scripts/post-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function fetchRemoteResources() {
for (const file of files) {
console.log(`[EXTRACT] Processing file: ${file}`);
const raw = fs.readFileSync(file, { encoding: 'utf-8' });
const src = raw.replaceAll(script, `/_astro/${name}`);
const src = raw.replaceAll(script, `/docs/_astro/${name}`);
fs.writeFileSync(file, src);
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ async function extractInlineResources() {
path.join(__astro, name),
await minifyJS(content)
);
script.setAttribute('src', `/_astro/${name}`);
script.setAttribute('src', `/docs/_astro/${name}`);
script.setAttribute('defer', '');
script.innerHTML = '';
}
Expand Down
Binary file added src/assets/img/social-preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions src/components/layout/BaseLayout.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import Icon from '@img/icon/icon.svg';
// import PreviewImage from '@assets/img/preview/main.jpg';
import PreviewImage from '@assets/img/social-preview.jpg';
import Footer from '@src/components/layout/Footer/Footer.astro';
import Navbar from '@src/components/layout/Navbar/Navbar.astro';
import '@src/styles/colors.scss';
Expand Down Expand Up @@ -29,8 +29,8 @@ const description =
Astro.props.description ??
"SurrealDB is the ultimate database for tomorrow's serverless, jamstack, single-page, and traditional applications.";
const type = Astro.props.type ?? 'website';
// const image = Astro.props.image ?? PreviewImage.src;
// const banner = 'banner' in Astro.props ? Astro.props.banner : defaultBanner;
const image = Astro.props.image ?? PreviewImage.src;
const banner = 'banner' in Astro.props ? Astro.props.banner : defaultBanner;
const { rssFeedName, navShadowBackground, navDarkDefault, footerBgMonochrome } =
Astro.props;
Expand Down Expand Up @@ -76,7 +76,7 @@ const url = new URL(
<meta name="og:description" property="og:description" content={description} />
<meta name="og:site_name" property="og:site_name" content="SurrealDB" />
<meta name="og:type" property="og:type" content={type} />
<!-- <meta name="og:image" property="og:image" content={image} /> -->
<meta name="og:image" property="og:image" content={image} />

{/* Social Network meta tags */}

Expand All @@ -85,8 +85,8 @@ const url = new URL(
<meta name="twitter:domain" property="twitter:domain" content="surrealdb.com" />
<meta name="twitter:title" property="twitter:title" content={title} />
<meta name="twitter:description" property="twitter:description" content={description} />
<!-- <meta name="twitter:image" property="twitter:image" content={image} /> -->
<!-- <meta name="twitter:image:src" property="twitter:image:src" content={image} /> -->
<meta name="twitter:image" property="twitter:image" content={image} />
<meta name="twitter:image:src" property="twitter:image:src" content={image} />
<meta name="twitter:image:alt" property="twitter:image:alt" content={description} />

</head>
Expand Down

0 comments on commit b457b8a

Please sign in to comment.