Skip to content

Commit

Permalink
Dynamic Sitemap - moved to greenwood plugins (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstockdi committed Jul 27, 2024
1 parent 53fb3b6 commit 9564d0c
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 51 deletions.
40 changes: 40 additions & 0 deletions packages/cli/src/plugins/copy/plugin-copy-sitemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { checkResourceExists } from "@greenwood/cli/src/lib/resource-utils.js";

Check failure on line 1 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

'checkResourceExists' is defined but never used

Check failure on line 1 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Strings must use singlequote

Check failure on line 1 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

'checkResourceExists' is defined but never used

Check failure on line 1 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Strings must use singlequote
import fs from 'fs/promises';


Check failure on line 4 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

More than 1 blank line not allowed

Check failure on line 4 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

More than 1 blank line not allowed
async function writeSitemap(compilation) {
try {

Check failure on line 6 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 2 spaces but found 4

Check failure on line 6 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 2 spaces but found 4
const { scratchDir, projectDirectory } = compilation.context;

Check failure on line 7 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6

Check failure on line 7 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6
const adapterScratchUrl = new URL('./sitemap.xml', scratchDir);

Check failure on line 8 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6

Check failure on line 8 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6

Check failure on line 9 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Trailing spaces not allowed

Check failure on line 9 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Trailing spaces not allowed
// Check if module exists

Check failure on line 10 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6

Check failure on line 10 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6
const sitemapModule = await import(`${projectDirectory}/src/sitemap.xml.js`);

Check failure on line 11 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6

Check failure on line 11 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6
const sitemap = await sitemapModule.generateSitemap(compilation);

Check failure on line 12 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6

Check failure on line 12 in packages/cli/src/plugins/copy/plugin-copy-sitemap.js

View workflow job for this annotation

GitHub Actions / build (18)

Expected indentation of 4 spaces but found 6

await fs.writeFile(adapterScratchUrl, sitemap);
console.info('Wrote sitemap to ./sitemap.xml');

return adapterScratchUrl;
} catch (error) {
console.error('Error in sitemapAdapter:', error);
}
}



const greenwoodPluginCopySitemap = [{
type: 'copy',
name: 'plugin-copy-sitemap',
provider: async (compilation) => {

const { outputDir } = compilation.context;
const sitemapScratchUrl = await writeSitemap(compilation);

return [{
from: sitemapScratchUrl,
to: new URL('./sitemap.xml', outputDir)
}];
}
}];

export { greenwoodPluginCopySitemap };
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
import fs from 'fs/promises';
import { ResourceInterface } from '@greenwood/cli/src/lib/resource-interface.js';

async function sitemapAdapter(compilation) {
try {
const { outputDir, projectDirectory } = compilation.context;
const adapterOutputUrl = new URL('./sitemap.xml', outputDir);

// Check if module exists
const sitemapModule = await import(`${projectDirectory}/src/sitemap.xml.js`);
const sitemap = await sitemapModule.generateSitemap(compilation);

await fs.writeFile(adapterOutputUrl, sitemap);
console.info('Wrote sitemap to ./sitemap.xml');
} catch (error) {
console.error('Error in sitemapAdapter:', error);
}
}

/*
*
* Sitemap
*
*/

class SitemapResource extends ResourceInterface {
constructor(compilation, options) {
super(compilation, options);
Expand Down Expand Up @@ -51,19 +28,10 @@ class SitemapResource extends ResourceInterface {

}

const greenwoodPluginSitemap = (options = {}) => [{
type: 'adapter',
name: 'plugin-adapter-sitemap',
provider: (compilation) => {
return async () => {
await sitemapAdapter(compilation, options);
};
}
},
{
const greenwoodPluginSitemap = {
type: 'resource',
name: 'plugin-sitemap',
name: 'plugin-resource-sitemap',
provider: (compilation, options) => new SitemapResource(compilation, options)
}];
};

export { greenwoodPluginSitemap };
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
plugins: []
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export default {
plugins: [
]
};

This file was deleted.

This file was deleted.

0 comments on commit 9564d0c

Please sign in to comment.