Add Astro.generator (#4012)
* feat: add generator property and component * chore: remove `Generator` component * chore: update generator description * chore: include generator in examples * chore: update lockfile * chore: format * fix: do not reference core from server runtime * chore: remove component test Co-authored-by: Nate Moore <nate@astro.build>
This commit is contained in:
parent
2c710e4edb
commit
f207c417e0
26 changed files with 101 additions and 0 deletions
18
.changeset/happy-peas-attend.md
Normal file
18
.changeset/happy-peas-attend.md
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Adds `Astro.generator` which can be used to add a [`<meta name="generator">`](https://html.spec.whatwg.org/multipage/semantics.html#meta-generator) tag.
|
||||||
|
|
||||||
|
```astro
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<footer>
|
||||||
|
<p>Built with <a href="https://astro.build">{Astro.generator}</a></p>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
```
|
|
@ -12,6 +12,7 @@ const { title } = Astro.props as Props;
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -14,6 +14,7 @@ const { title, description } = Astro.props;
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
|
|
||||||
<!-- Primary Meta Tags -->
|
<!-- Primary Meta Tags -->
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
|
|
|
@ -6,6 +6,7 @@ import * as Component from '@example/my-component';
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>Welcome to Astro</title>
|
<title>Welcome to Astro</title>
|
||||||
<style is:global>
|
<style is:global>
|
||||||
h {
|
h {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import '../styles/index.css';
|
||||||
<!-- Global Metadata -->
|
<!-- Global Metadata -->
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
|
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||||
<link rel="alternate icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="alternate icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
|
|
|
@ -12,6 +12,7 @@ console.log({ SSR, PUBLIC_SOME_KEY });
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>Astro</title>
|
<title>Astro</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter.astro';
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
|
|
|
@ -19,6 +19,7 @@ import SvelteCounter from '../components/SvelteCounter.svelte';
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter';
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
|
|
|
@ -13,6 +13,7 @@ const someProps = {
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter';
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter.svelte';
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter.vue';
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>Astro</title>
|
<title>Astro</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>Astro</title>
|
<title>Astro</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -9,6 +9,7 @@ const {
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="description" property="og:description" content={description} />
|
<meta name="description" property="og:description" content={description} />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
|
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
|
|
|
@ -11,6 +11,7 @@ import Time from '../components/Time.jsx';
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>Welcome to Astro</title>
|
<title>Welcome to Astro</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ const { title } = Astro.props as Props;
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -11,6 +11,7 @@ import Button from '../components/Button.astro';
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>Astro + TailwindCSS</title>
|
<title>Astro + TailwindCSS</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>Welcome to Astro</title>
|
<title>Welcome to Astro</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
@ -249,6 +249,16 @@ export interface AstroGlobalPartial {
|
||||||
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrosite)
|
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrosite)
|
||||||
*/
|
*/
|
||||||
site: URL | undefined;
|
site: URL | undefined;
|
||||||
|
/**
|
||||||
|
* Returns a string with the current version of Astro.
|
||||||
|
*
|
||||||
|
* Useful for using `<meta name="generator" content={Astro.generator} />` or crediting Astro in a site footer.
|
||||||
|
*
|
||||||
|
* [HTML Specification for `generator`](https://html.spec.whatwg.org/multipage/semantics.html#meta-generator)
|
||||||
|
*
|
||||||
|
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrogenerator)
|
||||||
|
*/
|
||||||
|
generator: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerConfig = {
|
type ServerConfig = {
|
||||||
|
|
|
@ -38,6 +38,8 @@ const htmlBooleanAttributes =
|
||||||
const htmlEnumAttributes = /^(contenteditable|draggable|spellcheck|value)$/i;
|
const htmlEnumAttributes = /^(contenteditable|draggable|spellcheck|value)$/i;
|
||||||
// Note: SVG is case-sensitive!
|
// Note: SVG is case-sensitive!
|
||||||
const svgEnumAttributes = /^(autoReverse|externalResourcesRequired|focusable|preserveAlpha)$/i;
|
const svgEnumAttributes = /^(autoReverse|externalResourcesRequired|focusable|preserveAlpha)$/i;
|
||||||
|
// process.env.PACKAGE_VERSION is injected when we build and publish the astro package.
|
||||||
|
const ASTRO_VERSION = process.env.PACKAGE_VERSION ?? 'development';
|
||||||
|
|
||||||
// INVESTIGATE:
|
// INVESTIGATE:
|
||||||
// 2. Less anys when possible and make it well known when they are needed.
|
// 2. Less anys when possible and make it well known when they are needed.
|
||||||
|
@ -530,6 +532,7 @@ export function createAstro(
|
||||||
const projectRoot = new URL(projectRootStr);
|
const projectRoot = new URL(projectRootStr);
|
||||||
return {
|
return {
|
||||||
site,
|
site,
|
||||||
|
generator: `Astro v${ASTRO_VERSION}`,
|
||||||
fetchContent: createDeprecatedFetchContentFn(),
|
fetchContent: createDeprecatedFetchContentFn(),
|
||||||
glob: createAstroGlobFn(),
|
glob: createAstroGlobFn(),
|
||||||
// INVESTIGATE is there a use-case for multi args?
|
// INVESTIGATE is there a use-case for multi args?
|
||||||
|
|
23
packages/astro/test/astro-generator.test.js
Normal file
23
packages/astro/test/astro-generator.test.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import * as cheerio from 'cheerio';
|
||||||
|
import { loadFixture } from './test-utils.js';
|
||||||
|
|
||||||
|
describe('Astro generator', () => {
|
||||||
|
let fixture;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
fixture = await loadFixture({
|
||||||
|
root: './fixtures/astro-generator/',
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('build', () => {
|
||||||
|
it('Defines Astro.generator', async () => {
|
||||||
|
const html = await fixture.readFile(`/index.html`);
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
|
||||||
|
expect($('meta[name="generator"]').attr('content')).to.match(/^Astro v/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
8
packages/astro/test/fixtures/astro-generator/package.json
vendored
Normal file
8
packages/astro/test/fixtures/astro-generator/package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"name": "@test/astro-generator",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
14
packages/astro/test/fixtures/astro-generator/src/pages/index.astro
vendored
Normal file
14
packages/astro/test/fixtures/astro-generator/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
let title = 'My App'
|
||||||
|
---
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="generator" content={Astro.generator}>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<footer>
|
||||||
|
Built with <a href="https://astro.build">{Astro.generator}</a>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1189,6 +1189,12 @@ importers:
|
||||||
'@astrojs/preact': link:../../../../integrations/preact
|
'@astrojs/preact': link:../../../../integrations/preact
|
||||||
astro: link:../../..
|
astro: link:../../..
|
||||||
|
|
||||||
|
packages/astro/test/fixtures/astro-generator:
|
||||||
|
specifiers:
|
||||||
|
astro: workspace:*
|
||||||
|
dependencies:
|
||||||
|
astro: link:../../..
|
||||||
|
|
||||||
packages/astro/test/fixtures/astro-get-static-paths:
|
packages/astro/test/fixtures/astro-get-static-paths:
|
||||||
specifiers:
|
specifiers:
|
||||||
astro: workspace:*
|
astro: workspace:*
|
||||||
|
|
Loading…
Reference in a new issue