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 name="viewport" content="width=device-width" />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>{title}</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -14,6 +14,7 @@ const { title, description } = Astro.props;
|
|||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
|
||||
<!-- Primary Meta Tags -->
|
||||
<title>{title}</title>
|
||||
|
|
|
@ -6,6 +6,7 @@ import * as Component from '@example/my-component';
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Welcome to Astro</title>
|
||||
<style is:global>
|
||||
h {
|
||||
|
|
|
@ -6,6 +6,7 @@ import '../styles/index.css';
|
|||
<!-- Global Metadata -->
|
||||
<meta charset="utf-8" />
|
||||
<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="alternate icon" type="image/x-icon" href="/favicon.ico" />
|
||||
|
|
|
@ -12,6 +12,7 @@ console.log({ SSR, PUBLIC_SOME_KEY });
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Astro</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter.astro';
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<style>
|
||||
html,
|
||||
|
|
|
@ -19,6 +19,7 @@ import SvelteCounter from '../components/SvelteCounter.svelte';
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter';
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<style>
|
||||
html,
|
||||
|
|
|
@ -13,6 +13,7 @@ const someProps = {
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<style>
|
||||
html,
|
||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter';
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<style>
|
||||
html,
|
||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter.svelte';
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<style>
|
||||
html,
|
||||
|
|
|
@ -10,6 +10,7 @@ import Counter from '../components/Counter.vue';
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<style>
|
||||
html,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Astro</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Astro</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -9,6 +9,7 @@ const {
|
|||
<meta charset="UTF-8" />
|
||||
<meta name="description" property="og:description" content={description} />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>{title}</title>
|
||||
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
|
|
|
@ -11,6 +11,7 @@ import Time from '../components/Time.jsx';
|
|||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Welcome to Astro</title>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ const { title } = Astro.props as Props;
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<title>{title}</title>
|
||||
</head>
|
||||
|
|
|
@ -11,6 +11,7 @@ import Button from '../components/Button.astro';
|
|||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Astro + TailwindCSS</title>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Welcome to Astro</title>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -249,6 +249,16 @@ export interface AstroGlobalPartial {
|
|||
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrosite)
|
||||
*/
|
||||
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 = {
|
||||
|
|
|
@ -38,6 +38,8 @@ const htmlBooleanAttributes =
|
|||
const htmlEnumAttributes = /^(contenteditable|draggable|spellcheck|value)$/i;
|
||||
// Note: SVG is case-sensitive!
|
||||
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:
|
||||
// 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);
|
||||
return {
|
||||
site,
|
||||
generator: `Astro v${ASTRO_VERSION}`,
|
||||
fetchContent: createDeprecatedFetchContentFn(),
|
||||
glob: createAstroGlobFn(),
|
||||
// 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
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/astro-generator:
|
||||
specifiers:
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/astro-get-static-paths:
|
||||
specifiers:
|
||||
astro: workspace:*
|
||||
|
|
Loading…
Reference in a new issue