Skip to content

Commit

Permalink
Merge pull request #21 from CloudCannon/feat/astro
Browse files Browse the repository at this point in the history
Flesh out Astro + misc build config
  • Loading branch information
bglw committed Sep 12, 2024
2 parents 203218f + 5f33861 commit 3ef700d
Show file tree
Hide file tree
Showing 305 changed files with 76,665 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ export async function generateConfiguration(filePaths, options) {
filePaths,
}),
),
paths: options?.config?.paths ?? undefined,
paths: options?.config?.paths ?? ssg.getPaths(),
timezone: options?.config?.timezone ?? ssg.getTimezone(),
markdown: options?.config?.markdown ?? ssg.generateMarkdown(config),
_snippets_imports: options?.config?._snippets_imports ?? ssg.getSnippetsImports()
},
};
}
Expand Down
108 changes: 106 additions & 2 deletions src/ssgs/astro.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,84 @@ export default class Astro extends Ssg {
super('astro');
}

/** @type {string[]} */
conventionalPathsInSource = ['src/', 'public/'];

/**
* @returns {string[]}
*/
configPaths() {
return ['astro.config.mjs', 'astro.config.cjs', 'astro.config.js', 'astro.config.ts'];
}

ignoredFolders() {
return super.ignoredFolders().concat([
'public/', // passthrough asset folder
'dist/', // default output
'.astro', // generated types
]);
}

templateExtensions() {
return super.templateExtensions().concat(['.astro', '.tsx', '.jsx', '.vue', '.svelte']);
}

/**
* Filters out collection paths that are collections, but exist in isolated locations.
* Used when a data folder (or similar) is causing all collections to group under one
* `collections_config` entry.
*
* @param collectionPaths {string[]}
* @param _options {{ config?: Record<string, any>; source?: string; basePath: string; }}
* @returns {string[]}
*/
filterContentCollectionPaths(collectionPaths, _options) {
return collectionPaths.filter(
(path) => path.startsWith('src/content') || path.startsWith('src/pages'),
);
}

/**
* Generates a collections config key from a path, avoiding existing keys.
*
* @param path {string}
* @param collectionsConfig {Record<string, any>}
* @returns {string}
*/
generateCollectionsConfigKey(path, collectionsConfig) {
const key = super.generateCollectionsConfigKey(path, collectionsConfig);

if (key.startsWith('content_')) {
const trimmedKey = key.replace('content_', '');
if (!Object.prototype.hasOwnProperty.call(collectionsConfig, trimmedKey)) {
return trimmedKey;
}
}

return key;
}

/**
* Generates a collection config entry.
*
* @param key {string}
* @param path {string}
* @param options {import('../types').GenerateCollectionConfigOptions}
* @returns {import('@cloudcannon/configuration-types').CollectionConfig}
*/
generateCollectionConfig(key, path, options) {
const collectionConfig = super.generateCollectionConfig(key, path, options);

if (
!collectionConfig.path?.startsWith('src/pages') &&
!collectionConfig.path?.startsWith('src/content')
) {
collectionConfig.disable_url = true;
}

return collectionConfig;
}

/**
* Generates a list of build suggestions.
*
Expand All @@ -17,13 +95,39 @@ export default class Astro extends Ssg {

commands.build.push({
value: 'npx astro build',
attribution: 'default for Astro sites',
attribution: 'most common for Astro sites',
});
commands.output.push({
value: 'dist',
attribution: 'default for Astro sites',
attribution: 'most common for Astro sites',
});

return commands;
}

/**
* Generates path configuration
*
* @returns {import('@cloudcannon/configuration-types').Paths | undefined}
*/
getPaths() {
return {
...super.getPaths(),
static: 'public',
uploads: 'public/uploads',
};
}

/**
* @param _config {Record<string, any> | undefined}
* @returns {import('@cloudcannon/configuration-types').MarkdownSettings}
*/
generateMarkdown(_config) {
return {
engine: 'commonmark',
options: {
gfm: true,
},
};
}
}
8 changes: 8 additions & 0 deletions src/ssgs/bridgetown.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export default class Bridgetown extends Ssg {
value: 'bundle install',
attribution: 'because of your Gemfile',
});
commands.preserved.push({
value: '.bundle_cache/',
attribution: 'recommended for speeding up bundler installs',
});
commands.environment['GEM_HOME'] = {
value: '/usr/local/__site/src/.bundle_cache/',
attribution: 'recommended for speeding up bundler installs',
};

if (options.source) {
commands.environment['BUNDLE_GEMFILE'] = {
Expand Down
27 changes: 27 additions & 0 deletions src/ssgs/hugo.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,31 @@ export default class Hugo extends Ssg {

return commands;
}

/**
* Generates path configuration
*
* @returns {import('@cloudcannon/configuration-types').SnippetsImports | undefined}
*/
getSnippetsImports() {
return {
...super.getSnippetsImports(),
hugo: {
exclude: ['hugo_instagram'],
},
};
}

/**
* Generates path configuration
*
* @returns {import('@cloudcannon/configuration-types').Paths | undefined}
*/
getPaths() {
return {
...super.getPaths(),
static: 'static',
uploads: 'static/uploads',
};
}
}
20 changes: 20 additions & 0 deletions src/ssgs/jekyll.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,14 @@ export default class Jekyll extends Ssg {
value: 'bundle exec jekyll build',
attribution: 'because of your Gemfile',
});
commands.preserved.push({
value: '.bundle_cache/',
attribution: 'recommended for speeding up bundler installs',
});
commands.environment['GEM_HOME'] = {
value: '/usr/local/__site/src/.bundle_cache/',
attribution: 'recommended for speeding up bundler installs',
};

if (options.source) {
commands.environment['BUNDLE_GEMFILE'] = {
Expand All @@ -415,4 +423,16 @@ export default class Jekyll extends Ssg {

return commands;
}

/**
* Generates path configuration
*
* @returns {import('@cloudcannon/configuration-types').SnippetsImports | undefined}
*/
getSnippetsImports() {
return {
...super.getSnippetsImports(),
jekyll: true
};
}
}
10 changes: 9 additions & 1 deletion src/ssgs/lume.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ export default class Lume extends Ssg {

commands.build.push({
value: 'deno task lume',
attribution: 'default for Lume sites',
attribution: 'most common for Lume sites',
});
commands.output.unshift({
value: '_site',
attribution: 'most common for Lume sites',
});
commands.preserved.push({
value: '.deno_cache/',
attribution: 'recommended for speeding up Deno installs',
});
commands.environment['DENO_DIR'] = {
value: '/usr/local/__site/src/.deno_cache/',
attribution: 'recommended for speeding up Deno installs',
};

return commands;
}
Expand Down
51 changes: 49 additions & 2 deletions src/ssgs/mkdocs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { joinPaths } from '../utility.js';
import Ssg from './ssg.js';

export default class MkDocs extends Ssg {
constructor() {
super('mkdocs');
}

/** @type {string[]} */
conventionalPathsInSource = ['docs/'];

/**
* @returns {string[]}
*/
configPaths() {
return ['mkdocs.yml'];
}

/**
* Generates a list of build suggestions.
*
Expand All @@ -14,16 +25,52 @@ export default class MkDocs extends Ssg {
*/
async generateBuildCommands(filePaths, options) {
const commands = await super.generateBuildCommands(filePaths, options);
const usePip = filePaths.includes(joinPaths([options.source, 'requirements.txt']));
const usePipEnv = filePaths.includes(joinPaths([options.source, 'Pipfile']));

commands.build.push({
value: 'npx mkdocs build',
attribution: 'default for MkDocs sites',
value: 'mkdocs build',
attribution: 'most common for MkDocs sites',
});
commands.output.unshift({
value: 'site',
attribution: 'most common for MkDocs sites',
});

if (usePip) {
commands.install.push({
value: 'pip install -r requirements.txt',
attribution: 'because of your `requirements.txt` file',
});

commands.environment['PIP_CACHE_DIR'] = {
value: '/usr/local/__site/src/.pip_cache/',
attribution: 'recommended for speeding up pip installs',
};

commands.preserved.push({
value: '.pip_cache/',
attribution: 'recommended for speeding up pip installs',
});
}

if (usePipEnv) {
commands.install.push({
value: 'pipenv install',
attribution: 'because of your `Pipfile`',
});

commands.environment['PIPENV_CACHE_DIR'] = {
value: '/usr/local/__site/src/.pipenv_cache/',
attribution: 'recommended for speeding up pipenv installs',
};

commands.preserved.push({
value: '.pipenv_cache/',
attribution: 'recommended for speeding up pipenv installs',
});
}

return commands;
}
}
8 changes: 6 additions & 2 deletions src/ssgs/next-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class NextJs extends Ssg {
}

templateExtensions() {
return super.templateExtensions().concat(['.tsx']);
return super.templateExtensions().concat(['.tsx', '.jsx']);
}

ignoredFolders() {
Expand All @@ -37,7 +37,11 @@ export default class NextJs extends Ssg {
});
commands.output.unshift({
value: 'out',
attribution: 'default for Next.js sites',
attribution: 'most common for Next.js sites',
});
commands.preserved.push({
value: '.next/',
attribution: 'recommended for Next.js sites',
});

return commands;
Expand Down
6 changes: 5 additions & 1 deletion src/ssgs/nuxt-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ export default class NuxtJs extends Ssg {

commands.build.push({
value: 'npx nuxt generate',
attribution: 'default for Nuxt sites',
attribution: 'most common for Nuxt sites',
});
commands.output.unshift({
value: 'dist',
attribution: 'most common for Nuxt sites',
});
commands.preserved.push({
value: '.nuxt/',
attribution: 'recommended for Nuxt sites',
});

return commands;
}
Expand Down
Loading

0 comments on commit 3ef700d

Please sign in to comment.