mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
START HERE
This commit is contained in:
parent
dd39fc8861
commit
10f3651824
5 changed files with 18 additions and 8 deletions
|
@ -2,7 +2,7 @@ import type babel from '@babel/core';
|
|||
import type vite from 'vite';
|
||||
import type { z } from 'zod';
|
||||
import type { AstroConfigSchema } from '../core/config';
|
||||
import type { AstroComponentFactory } from '../runtime/server';
|
||||
import type { AstroComponentFactory, Metadata } from '../runtime/server';
|
||||
|
||||
export interface AstroComponentMetadata {
|
||||
displayName: string;
|
||||
|
@ -141,6 +141,7 @@ export interface CollectionRSS {
|
|||
export interface ComponentInstance {
|
||||
default: AstroComponentFactory;
|
||||
css?: string[];
|
||||
$$metadata: Metadata;
|
||||
getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import { fileURLToPath } from 'url';
|
|||
import { createVite } from '../create-vite.js';
|
||||
import { pad } from '../dev/util.js';
|
||||
import { defaultLogOptions, levels, warn } from '../logger.js';
|
||||
import { ssr } from '../ssr/index.js';
|
||||
import { loadSsrModule, ssr } from '../ssr/index.js';
|
||||
import { generatePaginateFunction } from '../ssr/paginate.js';
|
||||
import { createRouteManifest, validateGetStaticPathsModule, validateGetStaticPathsResult } from '../ssr/routing.js';
|
||||
import { generateRssFunction } from '../ssr/rss.js';
|
||||
|
@ -75,6 +75,8 @@ class AstroBuilder {
|
|||
this.manifest.routes.map(async (route) => {
|
||||
const { pathname } = route;
|
||||
const filePath = new URL(`./${route.component}`, this.config.projectRoot);
|
||||
const { mod } = await loadSsrModule(filePath, this.config, viteServer);
|
||||
console.log("METADATA", mod.$$metadata);
|
||||
// static pages
|
||||
if (pathname) {
|
||||
allPages.push(
|
||||
|
|
|
@ -76,15 +76,22 @@ async function resolveRenderers(viteServer: ViteDevServer, ids: string[]): Promi
|
|||
return renderers;
|
||||
}
|
||||
|
||||
/** use Vite to SSR */
|
||||
export async function ssr({ astroConfig, filePath, logging, mode, origin, pathname, route, routeCache, viteServer }: SSROptions): Promise<string> {
|
||||
try {
|
||||
export async function loadSsrModule(filePath: URL, astroConfig: AstroConfig, viteServer: ViteDevServer) {
|
||||
// 1. resolve renderers
|
||||
// Important this happens before load module in case a renderer provides polyfills.
|
||||
const renderers = await resolveRenderers(viteServer, astroConfig.renderers);
|
||||
|
||||
// 1.5. load module
|
||||
const mod = (await viteServer.ssrLoadModule(fileURLToPath(filePath))) as ComponentInstance;
|
||||
return { renderers, mod };
|
||||
}
|
||||
|
||||
/** use Vite to SSR */
|
||||
export async function ssr({ astroConfig, filePath, logging, mode, origin, pathname, route, routeCache, viteServer }: SSROptions): Promise<string> {
|
||||
try {
|
||||
// 1.
|
||||
// Import the module and renderers
|
||||
const { renderers, mod } = await loadSsrModule(filePath, astroConfig, viteServer);
|
||||
|
||||
// 2. handle dynamic routes
|
||||
let params: Params = {};
|
||||
|
|
|
@ -6,7 +6,7 @@ import { pathToFileURL } from 'url';
|
|||
import { valueToEstree } from 'estree-util-value-to-estree';
|
||||
import * as astring from 'astring';
|
||||
import shorthash from 'shorthash';
|
||||
export { createMetadata } from './metadata.js';
|
||||
export { createMetadata, Metadata } from './metadata.js';
|
||||
|
||||
const { generate, GENERATOR } = astring;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ interface ComponentMetadata {
|
|||
componentUrl: string;
|
||||
}
|
||||
|
||||
class Metadata {
|
||||
export class Metadata {
|
||||
public fileURL: URL;
|
||||
private metadataCache: Map<any, ComponentMetadata | null>;
|
||||
constructor(fileURL: string, public modules: ModuleInfo[], components: any[]) {
|
||||
|
|
Loading…
Reference in a new issue