Skip to content

Commit

Permalink
Merge pull request #41 from samcyn/release-fix
Browse files Browse the repository at this point in the history
Release fix
  • Loading branch information
samcyn authored Apr 18, 2024
2 parents 90f68af + 4793177 commit 160ff3d
Show file tree
Hide file tree
Showing 40 changed files with 3,226 additions and 271 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = {
},
overrides: [
{
files: [`packages/site/src/pages/*.tsx`],
files: [`packages/site/src/**/*.tsx`],
rules: {
'@typescript-eslint/naming-convention': 0,
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"serve:site": "yarn workspace site serve",
"lint": "eslint . --ext .ts,.tsx,.js",
"lint:fix": "yarn lint --fix",
"clean:plugin": "yarn workspace plugin clean",
"clean:plugin": "yarn workspace gatsby-source-hubspot-node clean",
"clean:site": "yarn workspace site clean",
"clean": "npm-run-all -p 'clean:*'",
"husky": "husky",
Expand Down
16 changes: 0 additions & 16 deletions packages/plugin/__test__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ describe(`utils`, () => {
},
"mimeType": "image/jpg",
"parent": null,
"placeholderUrl": "undefined&w=%width%&h=%height%",
"url": undefined,
"width": undefined,
}
Expand All @@ -100,7 +99,6 @@ describe(`utils`, () => {
},
"mimeType": "image/jpg",
"parent": null,
"placeholderUrl": "https://images.unsplash.com/photo-1615751072497-5f5169febe17?fm=jpg&w=%width%&h=%height%",
"url": "https://images.unsplash.com/photo-1615751072497-5f5169febe17?fm=jpg",
"width": 3024,
}
Expand Down Expand Up @@ -150,20 +148,6 @@ describe(`utils`, () => {
expect(response.data).toBe('successful');
});
});

// it('should format URL correctly when endpoint already contains query parameters', async () => {
// const pluginOptions = {
// endpoint: 'https://example.com/api?key1=value1',
// requestOptions: {},
// searchParams: {
// param2: 'value2',
// },
// };

// await fetchRequest(pluginOptions);

// expect.deepEqual(fetch.mock.calls[0], ['https://example.com/api?key1=value1&param2=value2', expect.any(Object)]);
// });
});

// it('should use default method and headers if not provided in requestOptions', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin/src/on-plugin-init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { GatsbyNode } from 'gatsby';
import { ERROR_CODES } from './constants';
import { wrapWithAsterisks } from './utils';

/**
* Use the onPluginInit API to set up things that should be run before the plugin is initialized.
Expand All @@ -10,7 +11,10 @@ import { ERROR_CODES } from './constants';
* @see https://www.gatsbyjs.com/docs/reference/config-files/node-api-helpers/#reporter
*/
export const onPluginInit: GatsbyNode['onPluginInit'] = ({ reporter }) => {
reporter.info('Ye! Hubspot Blog Plugin Initialized. Check ReadMe.MD file for documentations');
const info = `Hey, thanks for considering installing "gatsby-source-hubspot-node",
for documentation see https://github.com/samcyn/gatsby-source-hubspot-node`;

reporter.info(wrapWithAsterisks(info));
reporter.setErrorMap({
[ERROR_CODES.HubspotSourcing]: {
text: (context) => `${context.sourceMessage}: ${context.errorCode}`,
Expand Down
24 changes: 17 additions & 7 deletions packages/plugin/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export async function fetchRequest<T = IPostInput>(
url += hasQueryParams ? `&${params.toString()}` : `?${params.toString()}`;
}

const { headers, method, ...rest } = requestOptions;
const { headers = {}, method = 'GET', ...rest } = requestOptions || {};

// Merge headers with defaultHeaders
const mergedHeaders = { ...defaultHeaders, ...headers };

const response = await fetch(url, {
method: method || 'GET',
headers: {
...defaultHeaders,
...headers,
},
method,
headers: mergedHeaders,
...rest,
});

Expand Down Expand Up @@ -120,7 +120,7 @@ export function createAssetNode(gatsbyApi: SourceNodesArgs, data: IPostImageInpu
filename: data.url,
width: data.width,
height: data.height,
placeholderUrl: `${data.url}&w=%width%&h=%height%`,
// placeholderUrl: `${data.url}&w=%width%&h=%height%`,
alt: data.alt,
parent: null,
children: [],
Expand All @@ -137,3 +137,13 @@ export function createAssetNode(gatsbyApi: SourceNodesArgs, data: IPostImageInpu
*/
return id;
}

export function wrapWithAsterisks(message: string) {
function createAsteriskLine(length: number) {
return '*'.repeat(length);
}

const asteriskLine = createAsteriskLine(message.length / 2);

return `${asteriskLine}*\n\n* ${message} *\n\n${asteriskLine}******`;
}
1 change: 0 additions & 1 deletion packages/site/gatsby-browser.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/site/gatsby-browser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as wrapPageElement } from './src/components/AppLayout';
74 changes: 69 additions & 5 deletions packages/site/gatsby-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const config: GatsbyConfig = {
title: `site`,
siteUrl: `https://www.samsoniyanda.com`,
},
// More easily incorporate content into your pages through automatic TypeScript type generation and better GraphQL IntelliSense.
// If you use VSCode you can also use the GraphQL plugin
// Learn more at: https://gatsby.dev/graphql-typegen
graphqlTypegen: true,
plugins: [
'gatsby-plugin-postcss',
Expand All @@ -25,9 +22,11 @@ const config: GatsbyConfig = {
icon: 'src/images/icon.png',
},
},
'gatsby-plugin-mdx',
'gatsby-plugin-sharp',
'gatsby-transformer-sharp',
{
resolve: 'gatsby-plugin-mdx',
},
{
resolve: 'gatsby-source-filesystem',
options: {
Expand All @@ -44,6 +43,14 @@ const config: GatsbyConfig = {
},
__key: 'pages',
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'mdx',
path: './src/docs/',
},
__key: 'mdx',
},
{
// using hubspot version 2. this is the default
resolve: 'gatsby-source-hubspot-node',
Expand All @@ -57,7 +64,7 @@ const config: GatsbyConfig = {
searchParams: {
state: 'PUBLISHED',
},
} satisfies IPluginOptions,
},
},
{
// using hubspot version 3.
Expand Down Expand Up @@ -131,6 +138,63 @@ const config: GatsbyConfig = {
},
} satisfies IPluginOptions,
},
{
resolve: 'gatsby-source-hubspot-node',
options: {
endpoint: 'https://api.github.com/repos/samcyn/gatsby-source-hubspot-node',
requestOptions: {
// todo take off not need in next version
headers: {},
},
nodeTypeOptions: {
nodeType: 'repository',
schemaCustomizationString: `
type Repository implements Node {
id: ID!
name: String
description: String
}
`,
apiResponseFormatter: (response) => [response],
nodeBuilderFormatter({ gatsbyApi, input, pluginOptions }) {
const id = gatsbyApi.createNodeId(`${pluginOptions.nodeType}-${input.data.id}`);
const node = {
...input.data,
id,
parent: null,
children: [],
internal: {
type: input.type,
contentDigest: gatsbyApi.createContentDigest(input.data),
},
} as NodeInput;
gatsbyApi.actions.createNode(node);
},
},
} satisfies IPluginOptions,
},
{
resolve: `gatsby-transformer-remark`,
options: {
footnotes: true,
gfm: true,
jsFrontmatterEngine: false,
plugins: [
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 740,
},
},
{
resolve: `gatsby-remark-responsive-iframe`,
options: {
wrapperStyle: `margin-bottom: 1.0725rem`,
},
},
],
},
},
],
};

Expand Down
56 changes: 56 additions & 0 deletions packages/site/gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { CreateWebpackConfigArgs, CreatePagesArgs } from 'gatsby';
import path from 'path';

exports.onCreateWebpackConfig = ({ actions }: CreateWebpackConfigArgs) => {
actions.setWebpackConfig({
resolve: {
alias: {
'@components': path.resolve(__dirname, 'src/components/'),
'@hooks': path.resolve(__dirname, 'src/hooks/'),
'@constants': path.resolve(__dirname, 'src/constants/'),
'@utils': path.resolve(__dirname, 'src/utils/'),
},
},
});
};

exports.createPages = async ({ graphql, actions, reporter }: CreatePagesArgs) => {
const { createPage } = actions;
const docPageTemplate = path.resolve(`src/templates/docs.tsx`);

const result = await graphql<Queries.GetAllDocumentsQuery>(`
query GetAllDocuments {
allMdx(filter: { frontmatter: { isPublished: { eq: true } } }) {
nodes {
id
frontmatter {
slug
title
tail
summary
date(formatString: "MMMM D, YYYY")
}
tableOfContents
internal {
contentFilePath
}
}
}
}
`);

if (result.errors) {
reporter.panicOnBuild('Error loading MDX result', result.errors);
}

result.data.allMdx.nodes.forEach((record) => {
createPage({
// Path for this page — required
path: `/docs/${record.frontmatter.slug}/`,
component: `${docPageTemplate}?__contentFilePath=${record.internal.contentFilePath}`,
context: {
...record,
},
});
});
};
1 change: 1 addition & 0 deletions packages/site/gatsby-ssr.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as wrapPageElement } from './src/components/AppLayout';
4 changes: 4 additions & 0 deletions packages/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
"gatsby-plugin-postcss": "^6.13.1",
"gatsby-plugin-sharp": "^5.13.1",
"gatsby-plugin-sitemap": "^6.13.1",
"gatsby-remark-images": "^7.13.1",
"gatsby-remark-responsive-iframe": "^6.13.1",
"gatsby-source-filesystem": "^5.13.1",
"gatsby-source-hubspot-node": "1.0.1",
"gatsby-transformer-remark": "^6.13.1",
"gatsby-transformer-sharp": "^5.13.1",
"postcss": "^8.4.38",
"react": "^18.2.0",
Expand Down
Loading

0 comments on commit 160ff3d

Please sign in to comment.