hmx ☞ astro (#22)
This changes all hmx files to astro files and updates all code to not reference hmx any more.
This commit is contained in:
parent
5c1cd5b1da
commit
3c24faa8ca
86 changed files with 129 additions and 127 deletions
|
@ -1,7 +1,7 @@
|
|||
|
||||
export default {
|
||||
projectRoot: '.',
|
||||
hmxRoot: './astro',
|
||||
astroRoot: './astro',
|
||||
dist: './_site',
|
||||
extensions: {
|
||||
'.jsx': 'preact'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
import Banner from '../components/Banner.hmx';
|
||||
import Nav from '../components/Nav.hmx';
|
||||
import Banner from '../components/Banner.astro';
|
||||
import Nav from '../components/Nav.astro';
|
||||
export function setup({ context }) {
|
||||
return {
|
||||
context: {
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
import Menu from '../components/Menu.hmx';
|
||||
import Subnav from '../components/Subnav.hmx';
|
||||
import Menu from '../components/Menu.astro';
|
||||
import Subnav from '../components/Subnav.astro';
|
||||
|
||||
export const layout = 'layouts/base.hmx';
|
||||
export const layout = 'layouts/base.astro';
|
||||
export function setup({ context }) {
|
||||
return {};
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
import Subnav from '../components/Subnav.hmx';
|
||||
import Menu from '../components/Menu.hmx';
|
||||
import Subnav from '../components/Subnav.astro';
|
||||
import Menu from '../components/Menu.astro';
|
||||
|
||||
export const layout = 'layouts/base.hmx';
|
||||
export const layout = 'layouts/base.astro';
|
||||
export function setup({ context }) {
|
||||
return {
|
||||
context: {
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
import Menu from '../components/Menu.hmx';
|
||||
export const layout = 'layouts/base.hmx';
|
||||
import Menu from '../components/Menu.astro';
|
||||
export const layout = 'layouts/base.astro';
|
||||
export function setup({ context }) {
|
||||
return {};
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
import { format as formatDate, parseISO } from 'date-fns';
|
||||
export const layout = 'layouts/base.hmx';
|
||||
export const layout = 'layouts/base.astro';
|
||||
export function setup({ context }) {
|
||||
return {};
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
export const layout = 'layouts/main.hmx';
|
||||
export const layout = 'layouts/main.astro';
|
||||
|
||||
export function setup({ context }) {
|
||||
return {
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: The Build Pipeline
|
||||
description: Snowpack Build creates a production-ready website with or without a bundler
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: The Dev Server
|
||||
description: Snowpack's dev server is fast because it only rebuilds the files you change. Powered by ESM (ES modules).
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: HMR + Fast Refresh
|
||||
description: Snowpack's ESM-powered unbundled development means near-instant single file builds that only take 10-25ms to load and update in the browser.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: How Snowpack Works
|
||||
description: Snowpack serves your application unbundled during development. Each file is built only once and is cached until it changes.
|
||||
---
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
import Card from '../components/Card.jsx';
|
||||
|
||||
export const layout = 'layouts/main.hmx';
|
||||
export const layout = 'layouts/main.astro';
|
||||
|
||||
// mocked for now, to be added later
|
||||
// 1. import {paginate} from 'magicthing';
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: 'Babel'
|
||||
tags: communityGuide
|
||||
published: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: The Snowpack Guide to connecting your favorite tools
|
||||
description: 'How do you use your favorite tools in Snowpack? This Guide will help you get started'
|
||||
published: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Hot Module Replacement (HMR)
|
||||
description: Enable Snowpack's Hot Module Replacement (HMR) on your development server.
|
||||
published: false
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: SSL Certificates
|
||||
description: How to use HTTPs during development and generate SSL certifcates for your Snowpack build.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: 'Jest'
|
||||
tags: communityGuide
|
||||
img: '/img/logos/jest.svg'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Optimize & Bundle for Production
|
||||
published: true
|
||||
description: How to optimize your Snowpack build for production, with or without a bundler.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Creating Your Own Plugin
|
||||
description: Learn the basics of our Plugin API through working examples.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: 'PostCSS'
|
||||
tags: communityGuide
|
||||
published: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Preact
|
||||
tags: communityGuide
|
||||
img: '/img/logos/preact.svg'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: React + babel-plugin-import-global
|
||||
published: false
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: React + Loadable Components
|
||||
published: false
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Routing
|
||||
published: true
|
||||
description: This guide will walk you through some common routing scenarios and how to configure the routes option to support them in development.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: 'Sass'
|
||||
tags: communityGuide
|
||||
published: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Server-Side Rendering (SSR)
|
||||
description: This guide will walk you through three different options for setting up Snowpack with your own custom server.
|
||||
published: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Streaming Imports
|
||||
published: true
|
||||
stream: Fetch your npm dependencies on-demand from a remote ESM CDN.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: 'Tailwind CSS'
|
||||
tags: communityGuide
|
||||
published: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Testing
|
||||
published: true
|
||||
description: How to choose and use a JavaScript test runner for your Snowpack site.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Snowpack Upgrade Guide
|
||||
published: true
|
||||
description: How to upgrade to Snowpack v3 from older versions of Snowpack.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Vue
|
||||
tags: communityGuide
|
||||
img: '/img/logos/vue.png'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: 'WASM'
|
||||
tags: communityGuide
|
||||
published: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: '@web/test-runner'
|
||||
tags: communityGuide
|
||||
img: '/img/logos/modern-web.svg'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: 'Web Workers'
|
||||
tags: communityGuide
|
||||
published: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Workbox
|
||||
tags: communityGuide
|
||||
description: The Workbox CLI integrates well with Snowpack.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
import Menu from '../components/Menu.hmx';
|
||||
import Hero from '../components/Hero.hmx';
|
||||
import Menu from '../components/Menu.astro';
|
||||
import Hero from '../components/Hero.astro';
|
||||
|
||||
export const layout = 'layouts/base.hmx';
|
||||
export const layout = 'layouts/base.astro';
|
||||
export function setup({ context }) {
|
||||
return {};
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
import NewsAssets from '../components/NewsAssets.svelte';
|
||||
import NewsTitle from '../components/NewsTitle.vue';
|
||||
|
||||
export const layout = 'layouts/main.hmx';
|
||||
export const layout = 'layouts/main.astro';
|
||||
|
||||
import news from '../data/news.json';
|
||||
import users from '../data/users.json';
|
|
@ -3,7 +3,7 @@
|
|||
import users from '../data/users.json';
|
||||
import PluginSearchPage from '../components/PluginSearchPage.jsx';
|
||||
|
||||
export const layout = 'layouts/main.hmx';
|
||||
export const layout = 'layouts/main.astro';
|
||||
|
||||
export function setup({ context }) {
|
||||
return {
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/post.hmx
|
||||
layout: layouts/post.astro
|
||||
bannerVideo: '/img/extra-space-4.mp4'
|
||||
permalink: '/posts/2020-05-26-snowpack-2-0-release/'
|
||||
title: Snowpack v2.0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/post.hmx
|
||||
layout: layouts/post.astro
|
||||
title: Snowpack 2.7
|
||||
description: 'A new plugin API plus smaller, faster production builds.'
|
||||
tagline: v2.7.0 release post
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/post.hmx
|
||||
layout: layouts/post.astro
|
||||
title: 'Snowpack v3.0 Release Candidate'
|
||||
tagline: New features to change the way you build for the web.
|
||||
description: 'New features to change the way you build for the web. Snowpack v3.0 will release on January 6th, 2021 (the one-year anniversary of its original launch post). This is our biggest release yet with some serious new features, including a new way to load npm packages on-demand that lets you skip the `npm install` step entirely.'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/post.hmx
|
||||
layout: layouts/post.astro
|
||||
title: 'Snowpack v3.0'
|
||||
description: Snowpack v3.0 is here! Our biggest release yet with some serious new features, including pre-bundled streaming imports, built-in bundling & optimizations, new JavaScript APIs, and more.'
|
||||
date: 2021-01-13
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
---
|
||||
import Subnav from '../components/Subnav.hmx';
|
||||
import { content as Menu } from '../components/Menu.hmx';
|
||||
import Subnav from '../components/Subnav.astro';
|
||||
import { content as Menu } from '../components/Menu.astro';
|
||||
// import contentful from 'skypack:contentful';
|
||||
|
||||
export default async function ({ params }) {
|
||||
const entry = await contentful.getEntry(params.slug);
|
||||
return { title: entry.fields.title, description: entry.fields.description, layout: 'layouts/base.hmx', props: { entry } };
|
||||
return { title: entry.fields.title, description: entry.fields.description, layout: 'layouts/base.astro', props: { entry } };
|
||||
}
|
||||
---
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Command Line API
|
||||
description: The Snowpack Command Line tool's API, commands, and flags.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Common Error Details
|
||||
description: How to troubleshoot common issues and error messagesm, plus our resources for getting help.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: snowpack.config.js
|
||||
description: The Snowpack configuration API reference.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Environment Variables
|
||||
description: Using environment variables with Snowpack
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Hot Module Replacement (HMR) API
|
||||
description: Snowpack implements HMR via the esm-hmr spec, an attempted standard for ESM-based Hot Module Replacement (HMR).
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: JavaScript API
|
||||
description: Snowpack's JavaScript API is for anyone who wants to integrate with some custom build pipeline or server-side rendering engine.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Plugin API
|
||||
description: The Snowpack Plugin API and how to use it.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Supported Files
|
||||
description: Snowpack ships with built-in support for many file types including json, js, ts, jsx, css, css modules, and images.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: 'Starting a New Project'
|
||||
description: This guide shows you how to set up Snowpack from scratch in a Node.js project. Along the way learn key concepts of Snowpack and unbundled development.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: Quick Start
|
||||
description: A very basic guide for developers who want to run Snowpack as quickly as possible.
|
||||
---
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content-with-cover.hmx
|
||||
layout: layouts/content-with-cover.astro
|
||||
title: 'Getting Started with React'
|
||||
description: 'Get started with this in-depth tutorial on how to build React applications and websites with Snowpack and developer tools like React Fast Refresh'
|
||||
date: 2020-12-01
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content-with-cover.hmx
|
||||
layout: layouts/content-with-cover.astro
|
||||
title: 'Getting Started with Svelte'
|
||||
description: 'Get started with this in-depth tutorial on how to build Svelte applications and websites with Snowpack'
|
||||
date: 2020-12-01
|
||||
|
|
|
@ -5,10 +5,10 @@ const transformPromise = import('./lib/transform2.js');
|
|||
|
||||
module.exports = function (snowpackConfig, { resolve, extensions } = {}) {
|
||||
return {
|
||||
name: 'snowpack-hmx',
|
||||
name: 'snowpack-astro',
|
||||
knownEntrypoints: ['deepmerge'],
|
||||
resolve: {
|
||||
input: ['.hmx', '.md'],
|
||||
input: ['.astro', '.md'],
|
||||
output: ['.js'],
|
||||
},
|
||||
async load({ filePath }) {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
export interface AstroConfigRaw {
|
||||
dist: string;
|
||||
projectRoot: string;
|
||||
hmxRoot: string;
|
||||
astroRoot: string;
|
||||
jsx?: string;
|
||||
}
|
||||
|
||||
export type ValidExtensionPlugins = 'hmx' | 'react' | 'preact' | 'svelte' | 'vue';
|
||||
export type ValidExtensionPlugins = 'astro' | 'react' | 'preact' | 'svelte' | 'vue';
|
||||
|
||||
export interface AstroConfig {
|
||||
dist: string;
|
||||
projectRoot: URL;
|
||||
hmxRoot: URL;
|
||||
astroRoot: URL;
|
||||
extensions?: Record<string, ValidExtensionPlugins>
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ interface CodeGenOptions {
|
|||
}
|
||||
|
||||
function internalImport(internalPath: string) {
|
||||
return `/__hmx_internal__/${internalPath}`;
|
||||
return `/_astro_internal/${internalPath}`;
|
||||
}
|
||||
|
||||
function getAttributes(attrs: Attribute[]): Record<string, string> {
|
||||
|
@ -96,7 +96,7 @@ interface ComponentInfo {
|
|||
}
|
||||
|
||||
const defaultExtensions: Readonly<Record<string, ValidExtensionPlugins>> = {
|
||||
'.hmx': 'hmx',
|
||||
'.astro': 'astro',
|
||||
'.jsx': 'react',
|
||||
'.vue': 'vue',
|
||||
'.svelte': 'svelte'
|
||||
|
@ -117,9 +117,9 @@ function getComponentWrapper(_name: string, { type, url }: ComponentInfo, compil
|
|||
}
|
||||
|
||||
switch (plugin) {
|
||||
case 'hmx': {
|
||||
case 'astro': {
|
||||
if (kind) {
|
||||
throw new Error(`HMX does not support :${kind}`);
|
||||
throw new Error(`Astro does not support :${kind}`);
|
||||
}
|
||||
return {
|
||||
wrapper: name,
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# `hmx/compiler`
|
||||
# `astro/compiler`
|
||||
|
||||
This directory is a fork of `svelte/compiler`. It is meant to stay as close to the original source as possible, so that upstream changes are easy to integrate. Everything svelte-specific and unrelated to parsing (compiler, preprocess, etc) has been removed.
|
|
@ -226,7 +226,7 @@ export default function parse(template: string, options: ParserOptions = {}): As
|
|||
parser.error(
|
||||
{
|
||||
code: 'duplicate-style',
|
||||
message: 'You can only have one <style> tag per HMX file',
|
||||
message: 'You can only have one <style> tag per Astro file',
|
||||
},
|
||||
parser.css[1].start
|
||||
);
|
||||
|
@ -234,15 +234,15 @@ export default function parse(template: string, options: ParserOptions = {}): As
|
|||
|
||||
// const instance_scripts = parser.js.filter((script) => script.context === 'default');
|
||||
// const module_scripts = parser.js.filter((script) => script.context === 'module');
|
||||
const hmx_scripts = parser.js.filter((script) => script.context === 'setup');
|
||||
const astro_scripts = parser.js.filter((script) => script.context === 'setup');
|
||||
|
||||
if (hmx_scripts.length > 1) {
|
||||
if (astro_scripts.length > 1) {
|
||||
parser.error(
|
||||
{
|
||||
code: 'invalid-script',
|
||||
message: 'A component can only have one frontmatter (---) script',
|
||||
},
|
||||
hmx_scripts[1].start
|
||||
astro_scripts[1].start
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -260,6 +260,6 @@ export default function parse(template: string, options: ParserOptions = {}): As
|
|||
html: parser.html,
|
||||
css: parser.css[0],
|
||||
// instance: instance_scripts[0],
|
||||
module: hmx_scripts[0],
|
||||
module: astro_scripts[0],
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,6 +17,6 @@ export async function loadConfig(rawRoot: string | undefined): Promise<AstroConf
|
|||
|
||||
const astroConfig: AstroConfig = (await import(astroConfigPath)).default;
|
||||
astroConfig.projectRoot = new URL(astroConfig.projectRoot + '/', fileProtocolRoot);
|
||||
astroConfig.hmxRoot = new URL(astroConfig.hmxRoot + '/', fileProtocolRoot);
|
||||
astroConfig.astroRoot = new URL(astroConfig.astroRoot + '/', fileProtocolRoot);
|
||||
return astroConfig;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ export default async function (astroConfig: AstroConfig) {
|
|||
break;
|
||||
}
|
||||
default: {
|
||||
error(logging, 'executing hmx', result.error);
|
||||
error(logging, 'executing astro', result.error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export type HProps = Record<string, string> | null | undefined;
|
||||
export type HChild = string | undefined | (() => string);
|
||||
export type HMXComponent = (props: HProps, ...children: Array<HChild>) => string;
|
||||
export type HTag = string | HMXComponent;
|
||||
export type AstroComponent = (props: HProps, ...children: Array<HChild>) => string;
|
||||
export type HTag = string | AstroComponent;
|
||||
|
||||
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
||||
|
||||
|
@ -41,7 +41,7 @@ function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
|
|||
export async function h(tag: HTag, attrs: HProps, ...pChildren: Array<Promise<HChild>>) {
|
||||
const children = await Promise.all(pChildren.flat(Infinity));
|
||||
if (typeof tag === 'function') {
|
||||
// We assume it's an hmx component
|
||||
// We assume it's an astro component
|
||||
return tag(attrs, ...children);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ async function* allPages(root: URL): AsyncGenerator<URL, void, unknown> {
|
|||
}
|
||||
|
||||
export default async function (astroConfig: AstroConfig) {
|
||||
const { projectRoot, hmxRoot } = astroConfig;
|
||||
const pageRoot = new URL('./pages/', hmxRoot);
|
||||
const { projectRoot, astroRoot } = astroConfig;
|
||||
const pageRoot = new URL('./pages/', astroRoot);
|
||||
const dist = new URL(astroConfig.dist + '/', projectRoot);
|
||||
|
||||
const configPath = new URL('./snowpack.config.js', projectRoot).pathname;
|
||||
|
@ -39,11 +39,11 @@ export default async function (astroConfig: AstroConfig) {
|
|||
const runtime = snowpack.getServerRuntime();
|
||||
|
||||
for await (const filepath of allPages(pageRoot)) {
|
||||
const rel = pathRelative(hmxRoot.pathname, filepath.pathname); // pages/index.hmx
|
||||
const pagePath = `/_hmx/${rel.replace(/\.(hmx|md)/, '.js')}`;
|
||||
const rel = pathRelative(astroRoot.pathname, filepath.pathname); // pages/index.astro
|
||||
const pagePath = `/_astro/${rel.replace(/\.(astro|md)/, '.js')}`;
|
||||
|
||||
try {
|
||||
const outPath = new URL('./' + rel.replace(/\.(hmx|md)/, '.html'), dist);
|
||||
const outPath = new URL('./' + rel.replace(/\.(astro|md)/, '.html'), dist);
|
||||
const outFolder = new URL('./', outPath);
|
||||
const mod = await runtime.importModule(pagePath);
|
||||
const html = await mod.exports.default({});
|
||||
|
|
|
@ -28,18 +28,18 @@ export type LoadResult = LoadResultSuccess | LoadResultNotFound | LoadResultErro
|
|||
|
||||
async function load(config: RuntimeConfig, rawPathname: string | undefined): Promise<LoadResult> {
|
||||
const { logging, snowpack, snowpackRuntime } = config;
|
||||
const { hmxRoot } = config.astroConfig;
|
||||
const { astroRoot } = config.astroConfig;
|
||||
|
||||
const fullurl = new URL(rawPathname || '/', 'https://example.org/');
|
||||
const reqPath = decodeURI(fullurl.pathname);
|
||||
const selectedPage = reqPath.substr(1) || 'index';
|
||||
info(logging, 'access', reqPath);
|
||||
|
||||
const selectedPageLoc = new URL(`./pages/${selectedPage}.hmx`, hmxRoot);
|
||||
const selectedPageMdLoc = new URL(`./pages/${selectedPage}.md`, hmxRoot);
|
||||
const selectedPageUrl = `/_hmx/pages/${selectedPage}.js`;
|
||||
const selectedPageLoc = new URL(`./pages/${selectedPage}.astro`, astroRoot);
|
||||
const selectedPageMdLoc = new URL(`./pages/${selectedPage}.md`, astroRoot);
|
||||
const selectedPageUrl = `/_astro/pages/${selectedPage}.js`;
|
||||
|
||||
// Non-hmx pages (file resources)
|
||||
// Non-Astro pages (file resources)
|
||||
if (!existsSync(selectedPageLoc) && !existsSync(selectedPageMdLoc)) {
|
||||
try {
|
||||
const result = await snowpack.loadUrl(reqPath);
|
||||
|
@ -96,19 +96,19 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro
|
|||
}
|
||||
|
||||
export async function createRuntime(astroConfig: AstroConfig, logging: LogOptions) {
|
||||
const { projectRoot, hmxRoot, extensions } = astroConfig;
|
||||
const { projectRoot, astroRoot, extensions } = astroConfig;
|
||||
|
||||
const internalPath = new URL('./frontend/', import.meta.url);
|
||||
|
||||
// Workaround for SKY-251
|
||||
const hmxPlugOptions: {
|
||||
const astroPlugOptions: {
|
||||
resolve?: (s: string) => string;
|
||||
extensions?: Record<string, string>
|
||||
} = { extensions };
|
||||
if (existsSync(new URL('./package-lock.json', projectRoot))) {
|
||||
const pkgLockStr = await readFile(new URL('./package-lock.json', projectRoot), 'utf-8');
|
||||
const pkgLock = JSON.parse(pkgLockStr);
|
||||
hmxPlugOptions.resolve = (pkgName: string) => {
|
||||
astroPlugOptions.resolve = (pkgName: string) => {
|
||||
const ver = pkgLock.dependencies[pkgName].version;
|
||||
return `/_snowpack/pkg/${pkgName}.v${ver}.js`;
|
||||
};
|
||||
|
@ -117,10 +117,10 @@ export async function createRuntime(astroConfig: AstroConfig, logging: LogOption
|
|||
const snowpackConfig = await loadConfiguration({
|
||||
root: projectRoot.pathname,
|
||||
mount: {
|
||||
[hmxRoot.pathname]: '/_hmx',
|
||||
[internalPath.pathname]: '/__hmx_internal__',
|
||||
[astroRoot.pathname]: '/_astro',
|
||||
[internalPath.pathname]: '/_astro_internal',
|
||||
},
|
||||
plugins: [[new URL('../snowpack-plugin.cjs', import.meta.url).pathname, hmxPlugOptions]],
|
||||
plugins: [[new URL('../snowpack-plugin.cjs', import.meta.url).pathname, astroPlugOptions]],
|
||||
devOptions: {
|
||||
open: 'none',
|
||||
output: 'stream',
|
||||
|
|
|
@ -24,16 +24,16 @@ const defaultCompileOptions: CompileOptions = {
|
|||
};
|
||||
|
||||
function internalImport(internalPath: string) {
|
||||
return `/__hmx_internal__/${internalPath}`;
|
||||
return `/_astro_internal/${internalPath}`;
|
||||
}
|
||||
|
||||
interface ConvertHmxOptions {
|
||||
interface ConvertAstroOptions {
|
||||
compileOptions: CompileOptions;
|
||||
filename: string;
|
||||
fileID: string;
|
||||
}
|
||||
|
||||
async function convertHmxToJsx(template: string, opts: ConvertHmxOptions): Promise<TransformResult> {
|
||||
async function convertAstroToJsx(template: string, opts: ConvertAstroOptions): Promise<TransformResult> {
|
||||
const { filename } = opts;
|
||||
|
||||
// 1. Parse
|
||||
|
@ -90,17 +90,19 @@ async function convertMdToJsx(
|
|||
|
||||
const convertOptions = { compileOptions, filename, fileID };
|
||||
|
||||
return convertHmxToJsx(raw, convertOptions);
|
||||
return convertAstroToJsx(raw, convertOptions);
|
||||
}
|
||||
|
||||
type SupportedExtensions = '.astro' | '.md';
|
||||
|
||||
async function transformFromSource(
|
||||
contents: string,
|
||||
{ compileOptions, filename, projectRoot }: { compileOptions: CompileOptions; filename: string; projectRoot: string }
|
||||
): Promise<TransformResult> {
|
||||
const fileID = path.relative(projectRoot, filename);
|
||||
switch (path.extname(filename)) {
|
||||
case '.hmx':
|
||||
return convertHmxToJsx(contents, { compileOptions, filename, fileID });
|
||||
switch (path.extname(filename) as SupportedExtensions) {
|
||||
case '.astro':
|
||||
return convertAstroToJsx(contents, { compileOptions, filename, fileID });
|
||||
case '.md':
|
||||
return convertMdToJsx(contents, { compileOptions, filename, fileID });
|
||||
default:
|
||||
|
@ -125,7 +127,7 @@ export async function compileComponent(
|
|||
// <script astro></script>
|
||||
${sourceJsx.script}
|
||||
|
||||
// \`__render()\`: Render the contents of the HMX module. "<slot:*>" elements are not
|
||||
// \`__render()\`: Render the contents of the Astro module. "<slot:*>" elements are not
|
||||
// included (see below).
|
||||
import { h, Fragment } from '${internalImport('h.js')}';
|
||||
export function __slothead(children, context) { return h(Fragment, null, ${headItemJsx}); }
|
||||
|
@ -135,7 +137,7 @@ export default __render;
|
|||
|
||||
if (headItemJsx) {
|
||||
modJsx += `
|
||||
// \`__renderPage()\`: Render the contents of the HMX module as a page. This is a special flow,
|
||||
// \`__renderPage()\`: Render the contents of the Astro module as a page. This is a special flow,
|
||||
// triggered by loading a component directly by URL.
|
||||
// If the page exports a defined "layout", then load + render those first. "context", "astro:head",
|
||||
// and "slot:body" should all inherit from parent layouts, merging together in the correct order.
|
||||
|
@ -149,7 +151,7 @@ export async function __renderPage({request, children}) {
|
|||
|
||||
// find all layouts, going up the layout chain.
|
||||
if (currentChild.layout) {
|
||||
const layoutComponent = (await import('/_hmx/layouts/' + layout.replace(/.*layouts\\//, "").replace(/\.hmx$/, '.js')));
|
||||
const layoutComponent = (await import('/_astro/layouts/' + layout.replace(/.*layouts\\//, "").replace(/\.astro$/, '.js')));
|
||||
return layoutComponent.__renderPage({
|
||||
request,
|
||||
children: [currentChild, ...children],
|
||||
|
|
|
@ -9,8 +9,8 @@ let runtime;
|
|||
|
||||
Basics.before(async () => {
|
||||
const astroConfig = {
|
||||
projectRoot: new URL('./fixtures/hmx-basic/', import.meta.url),
|
||||
hmxRoot: new URL('./fixtures/hmx-basic/astro/', import.meta.url),
|
||||
projectRoot: new URL('./fixtures/astro-basic/', import.meta.url),
|
||||
hmxRoot: new URL('./fixtures/astro-basic/astro/', import.meta.url),
|
||||
dist: './_site'
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,7 @@ Basics.after(async () => {
|
|||
await runtime && runtime.shutdown();
|
||||
});
|
||||
|
||||
Basics('Can load hmx page', async () => {
|
||||
Basics('Can load page', async () => {
|
||||
const result = await runtime.load('/');
|
||||
|
||||
assert.equal(result.statusCode, 200);
|
|
@ -4,12 +4,12 @@ import { createRuntime } from '../lib/runtime.js';
|
|||
import { loadConfig } from '../lib/config.js';
|
||||
import { doc } from './test-utils.js';
|
||||
|
||||
const HMXMD = suite('HMX Markdown');
|
||||
const Markdown = suite('Astro Markdown');
|
||||
|
||||
let runtime, setupError;
|
||||
|
||||
HMXMD.before(async () => {
|
||||
const astroConfig = await loadConfig(new URL('./fixtures/hmx-markdown', import.meta.url).pathname);
|
||||
Markdown.before(async () => {
|
||||
const astroConfig = await loadConfig(new URL('./fixtures/astro-markdown', import.meta.url).pathname);
|
||||
|
||||
const logging = {
|
||||
level: 'error',
|
||||
|
@ -24,15 +24,15 @@ HMXMD.before(async () => {
|
|||
}
|
||||
});
|
||||
|
||||
HMXMD.after(async () => {
|
||||
Markdown.after(async () => {
|
||||
runtime && runtime.shutdown();
|
||||
});
|
||||
|
||||
HMXMD('No errors creating a runtime', () => {
|
||||
Markdown('No errors creating a runtime', () => {
|
||||
assert.equal(setupError, undefined);
|
||||
});
|
||||
|
||||
HMXMD('Can load markdown pages with hmx', async () => {
|
||||
Markdown('Can load markdown pages with hmx', async () => {
|
||||
const result = await runtime.load('/post');
|
||||
|
||||
assert.equal(result.statusCode, 200);
|
||||
|
@ -42,4 +42,4 @@ HMXMD('Can load markdown pages with hmx', async () => {
|
|||
assert.ok($('#test').length, 'There is a div added via a component from markdown');
|
||||
});
|
||||
|
||||
HMXMD.run();
|
||||
Markdown.run();
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
export default {
|
||||
projectRoot: '.',
|
||||
hmxRoot: './astro',
|
||||
astroRoot: './astro',
|
||||
dist: './_site'
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
export default {
|
||||
projectRoot: '.',
|
||||
hmxRoot: './astro',
|
||||
astroRoot: './astro',
|
||||
dist: './_site',
|
||||
extensions: {
|
||||
'.jsx': 'preact'
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
layout: layouts/content.hmx
|
||||
layout: layouts/content.astro
|
||||
title: My Blog Post
|
||||
description: This is a post about some stuff.
|
||||
import:
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
export default {
|
||||
projectRoot: '.',
|
||||
hmxRoot: './astro',
|
||||
astroRoot: './astro',
|
||||
dist: './_site'
|
||||
// No extensions needed, React is the default.
|
||||
}
|
|
@ -32,7 +32,7 @@ React('No error creating the runtime', () => {
|
|||
assert.equal(setupError, undefined);
|
||||
});
|
||||
|
||||
React('Can load hmx page', async () => {
|
||||
React('Can load page', async () => {
|
||||
const result = await runtime.load('/');
|
||||
|
||||
assert.equal(result.statusCode, 200);
|
||||
|
|
|
@ -52,7 +52,7 @@ async function* allPageFiles(root) {
|
|||
|
||||
async function* allPages(root) {
|
||||
for await (let fileURL of allPageFiles(root)) {
|
||||
let bare = fileURL.pathname.replace(/\.(hmx|md)$/, '').replace(/index$/, '');
|
||||
let bare = fileURL.pathname.replace(/\.(astro|md)$/, '').replace(/index$/, '');
|
||||
|
||||
yield '/' + pathRelative(root.pathname, bare);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue