Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added improved docs #2410

Merged
merged 2 commits into from
Jan 26, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/pr-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
with:
node-version: ${{ env.NODE_VERSION }}
- run: yarn --frozen-lockfile --network-timeout 1000000
- run: yarn build-docs
env:
GITHUB_TOKEN: ${{ github.token }}
NODE_OPTIONS: '--max_old_space_size=4096' # Getting Javascript heap out of memory error. Increasing heap size
Expand All @@ -32,8 +31,8 @@ jobs:
- run: |
export CLOUDFLARE_API_TOKEN="${{ secrets.CLOUDFLARE_API_TOKEN }}"
export CLOUDFLARE_ACCOUNT_ID="${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"
cd site
npx wrangler@2 pages publish "src/.vuepress/dist" --project-name="altair-site"
cd packages/altair-docs
npx wrangler@2 pages publish ".vitepress/dist" --project-name="altair-site"
- run: |
export CLOUDFLARE_API_TOKEN="${{ secrets.CLOUDFLARE_API_TOKEN }}"
export CLOUDFLARE_ACCOUNT_ID="${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

.nx/
# compiled output
/tmp
/out-tsc
Expand Down
2 changes: 2 additions & 0 deletions packages/altair-docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vitepress/cache
.vitepress/dist
130 changes: 130 additions & 0 deletions packages/altair-docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { defineConfig } from 'vitepress'
import { getConfig } from './plugins/sidebar-generation';

const { sidebar: retrievedSidebar } = getConfig({
filter: meta => meta.sidebar !== false,
});

const seoTitle = 'Altair GraphQL Client';
const seoImage = '/assets/img/app-shot.png';
const description = 'Altair is a feature-rich GraphQL Client IDE for all platforms. Enables you interact with any GraphQL server you are authorized to access from any platform you are on.';
const GA = 'UA-41432833-7';
// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "Altair GraphQL Client",
description,
head: [
['link', { rel: 'icon', href: '/favicon.ico' }],
[
'script',
{ async: '', src: `https://www.googletagmanager.com/gtag/js?id=${GA}` }
],
[
'script',
{},
`window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA}');`
],

['meta', { name: 'theme-color', content: '#3eaf7c' }],
['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
[
'meta',
{ name: 'apple-mobile-web-app-status-bar-style', content: 'black' },
],
[
'link',
{
rel: 'stylesheet',
href:
'https://fonts.googleapis.com/css?family=DM+Sans:400,500,700&display=swap',
},
],
[
'link',
{
rel: 'stylesheet',
href:
'https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css',
},
],
[
'script',
{
src:
'https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js',
'data-cfasync': 'false',
},
],


// SEO
['meta', { name: 'description', content: description }],
['meta', { itemprop: 'name', content: seoTitle }],
['meta', { itemprop: 'description', content: description }],
['meta', { itemprop: 'image', content: seoImage }],
['meta', { name: 'author', content: 'Samuel Imolorhe' }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:title', content: seoTitle }],
['meta', { property: 'og:description', content: description }],
['meta', { property: 'og:image', content: seoImage }],
['meta', { property: 'twitter:card', content: 'summary_large_image' }],
['meta', { property: 'twitter:title', content: seoTitle }],
['meta', { property: 'twitter:description', content: description }],
['meta', { property: 'twitter:image', content: seoImage }],
],
cleanUrls: true,
themeConfig: {
logo: '/assets/img/altair_logo_128.png',
nav: [
{
text: 'Docs',
link: '/docs/',
},
{
text: 'Donate',
link: 'https://opencollective.com/altair/donate',
},
],
sidebar: [retrievedSidebar[0]],
socialLinks: [
{
icon: 'twitter',
link: 'https://twitter.com/AltairGraphQL',
},
{
icon: 'github',
link: 'https://github.com/altair-graphql/altair',
},
],
carbonAds: {
code: 'CEADPK37',
placement: 'altairsirmueldesign',
},
editLink: {
pattern: 'https://github.com/altair-graphql/altair/edit/main/packages/altair-docs/:path',
text: 'Help us improve this page!',
},
lastUpdated: {
text: 'Last Updated',
},
search: {
provider: 'local'
},
},
transformHead({ page }) {
// Skip the 404 page
if (page !== '404.md') {
const canonicalUrl = `https://altairgraphql.dev/${page}`
.replace(/index\.md$/, '')
.replace(/\.md$/, '')

return [['link', { rel: 'canonical', href: canonicalUrl }]]
}
},
sitemap: {
hostname: 'https://altairgraphql.dev',
}
})
76 changes: 76 additions & 0 deletions packages/altair-docs/.vitepress/plugins/github-metadata.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// https://github.com/jekyll/github-metadata/blob/master/docs/site.github.md
// https://octokit.github.io/rest.js/v18#repos-get-latest-release
import fs from 'fs';
import path from 'path';
import { Octokit } from '@octokit/rest';
import NodeCache from 'node-cache';
// Does the cache persist over several runs? 🤔
const myCache = new NodeCache( { stdTTL: 600 } );

const getGithubMetadata = async ({ owner = '', repo = '' }) => {

let githubToken = '';
try {
githubToken = fs.readFileSync(path.resolve(__dirname, './github-token'), 'utf-8');
} catch (error) {
console.log('no github token found');
}
githubToken ||= process.env.GITHUB_TOKEN ?? '';

const octokit = new Octokit({
auth: githubToken || undefined,
});

const repoUrl = `https://github.com/${owner}/${repo}`;

const resolvers = {
latest_release: async () => {
const fromCache = myCache.get('latest_release');
if (fromCache) {
return fromCache;
}
const { data } = await octokit.rest.repos.getLatestRelease({ owner, repo });
if (data) {
myCache.set('latest_release', data);
}
return data;
},
// This is greatly increasing the bundle size, but we are not using it!
// releases: async () => {
// const fromCache = myCache.get('releases');
// if (fromCache) {
// return fromCache;
// }
// const { data } = await octokit.rest.repos.listReleases({ owner, repo });
// if (data) {
// myCache.set('releases', data);
// }
// return data;
// },
releases_url: async () => `${repoUrl}/releases`,
}
const keys = Object.keys(resolvers);
const vls = await Promise.allSettled(keys.map(_ => resolvers[_]()));

return vls.reduce((acc, cur, i) => {
if (cur.status === 'rejected') {
console.log(cur);
return acc;
}
return {
...acc,
[keys[i]]: cur.value,
}
}, {});
};

declare const data: any;
export { data }

export default {
async load() {
const owner = 'altair-graphql';
const repo = 'altair';
return await getGithubMetadata({ owner, repo });
},
};