Skip to content

Commit

Permalink
use encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs committed Jan 31, 2024
1 parent b004d1e commit ce404db
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
12 changes: 8 additions & 4 deletions plugins/gatsby-source-snooty-prod/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ exports.sourceNodes = async ({ actions, createContentDigest, createNodeId }) =>
if (filename.endsWith('.txt') && !manifestMetadata.openapi_pages?.[key]) {
PAGES.push(key);
}
if (val?.ast?.options?.template === 'changelog') hasOpenAPIChangelog = true;
if (val?.ast?.options?.template === 'changelog') {
hasOpenAPIChangelog = true;
}
});

await createDocsetNodes({ db, createNode, createNodeId, createContentDigest });
Expand All @@ -170,11 +172,13 @@ exports.sourceNodes = async ({ actions, createContentDigest, createNodeId }) =>

await createRemoteMetadataNode({ createNode, createNodeId, createContentDigest }, umbrellaProduct);

if (siteMetadata.project === 'cloud-docs' && hasOpenAPIChangelog)
console.log('metadata ', siteMetadata);
console.log('has ', hasOpenAPIChangelog);
if (siteMetadata.project === 'cloud-docs' && hasOpenAPIChangelog) {
console.log('create changelog node');
await createOpenAPIChangelogNode({ createNode, createNodeId, createContentDigest, siteMetadata, db });
}

console.log('assets! ', assets);
console.log('assets size ', assets.size);
await saveAssetFiles(assets, db);
if (!siteMetadata.manifestPath) {
console.error('Getting metadata from realm without filters');
Expand Down
12 changes: 3 additions & 9 deletions src/init/DocumentDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ class RealmInterface {

class ManifestDocumentDatabase {
constructor(path) {
this.zip = null;
// this.zip = path.match(/\.zip$/) ? new AdmZip(path) : null;
this.zippy = path.match(/\.zip$/) ? new AdmZip(path) : null;
this.zip = path?.match(/\.zip$/) ? new AdmZip(path) : null;
this.realmInterface = new RealmInterface();
}

Expand All @@ -69,9 +67,7 @@ class ManifestDocumentDatabase {
async getDocuments() {
const result = [];
if (!this.zip) {
const documents = JSON.parse(
fs.readFileSync('/Users/matt.meigs/Desktop/docs-platform/snooty/snooty-documents.js')
);
const documents = JSON.parse(fs.readFileSync('snooty-documents.json'));
return documents;
} else {
const zipEntries = this.zip.getEntries();
Expand All @@ -91,9 +87,7 @@ class ManifestDocumentDatabase {

async getAsset(checksum) {
if (!this.zip) {
console.log(__dirname);
const asset = fs.readFileSync(`/Users/matt.meigs/Desktop/docs-platform/snooty/loaded-assets/${checksum}`);
console.log('ASSET? ', asset);
const asset = fs.readFileSync(`assets/${checksum}`, { encoding: 'base64' });
return asset;
}
const result = this.zip.getEntry(`assets/${checksum}`);
Expand Down
3 changes: 1 addition & 2 deletions src/utils/setup/fetch-manifest-metadata.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const AdmZip = require('adm-zip');
const BSON = require('bson');
const fs = require('fs');
const path = require('path');

// Returns the metadata from the manifest file if provided
const fetchManifestMetadata = () => {
let metadata = {};
if (!process.env.GATSBY_MANIFEST_PATH || !process.env.GATSBY_MANIFEST_PATH.match(/\.zip$/)) {
metadata = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../../snooty-metadata.js')));
metadata = JSON.parse(fs.readFileSync('snooty-metadata.json'));
return metadata;
}
if (process.env.GATSBY_MANIFEST_PATH) {
Expand Down
1 change: 0 additions & 1 deletion src/utils/setup/save-asset-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const saveFile = async (file, data) => {
});
await fs.writeFile(path.join('public', file), data, 'binary');
await fs.stat(path.join('public', file));
console.log('file ', path.join('public', file));
await fs.writeFile(path.join('public', file), data, 'binary');
};

Expand Down

0 comments on commit ce404db

Please sign in to comment.