@@ -792,36 +792,50 @@ export class Project {
792
792
const output = cleanCSS . minify ( css )
793
793
css = output . styles
794
794
}
795
- const hash = ( new Sha1 ) . update ( css ) . hex ( )
796
- const filepath = path . join (
797
- path . dirname ( mod . sourceFilePath ) ,
798
- util . trimSuffix ( path . basename ( mod . sourceFilePath ) , '.css' ) + '.' + hash . slice ( 0 , hashShort ) + '.css'
799
- )
800
- const asLink = css . length > 1024
801
- if ( asLink ) {
802
- await writeTextFile ( path . join ( this . buildDir , filepath ) , css )
803
- }
804
795
mod . jsContent = [
805
796
`import { applyCSS } from ${ JSON . stringify ( relativePath (
806
797
path . dirname ( mod . url ) ,
807
798
'/-/deno.land/x/aleph/head.js'
808
799
) ) } ;`,
809
- `applyCSS(${ JSON . stringify ( url ) } , ${ asLink ? JSON . stringify ( path . join ( this . config . baseUrl , '_aleph' , filepath ) ) + ', true' : JSON . stringify ( this . isDev ? `\n${ css } \n` : css ) } );` ,
800
+ `applyCSS(${ JSON . stringify ( url ) } , ${ JSON . stringify ( this . isDev ? `\n${ css } \n` : css ) } );` ,
810
801
] . join ( this . isDev ? '\n' : '' )
811
802
mod . jsSourceMap = ''
812
- mod . hash = hash
803
+ mod . hash = ( new Sha1 ) . update ( css ) . hex ( )
813
804
} else if ( mod . sourceType === 'sass' || mod . sourceType === 'scss' ) {
814
805
// todo: support sass
815
- } else if ( mod . sourceType === 'md' || mod . sourceType === 'mdx' ) {
806
+ } else if ( mod . sourceType === 'mdx' ) {
807
+ // todo: support mdx
808
+ } else if ( mod . sourceType === 'md' || mod . sourceType === 'markdown' ) {
816
809
const { __content, ...props } = safeLoadFront ( sourceContent )
817
810
const html = marked . parse ( __content )
818
811
mod . jsContent = [
819
- `import React from ${ JSON . stringify ( relativePath ( path . dirname ( mod . sourceFilePath ) , '/-/esm.sh/react.js' ) ) } ;` ,
820
- `export default function Markdown() {` ,
821
- ` return React.createElement("div", ${ JSON . stringify ( { className : 'markdown' , dangerouslySetInnerHTML : { __html : html } } ) } );` ,
812
+ this . isDev && `const _s = $RefreshSig$();` ,
813
+ `import React, { useEffect, useRef } from ${ JSON . stringify ( relativePath ( path . dirname ( mod . sourceFilePath ) , '/-/esm.sh/react.js' ) ) } ;` ,
814
+ `import { redirect } from ${ JSON . stringify ( relativePath ( path . dirname ( mod . sourceFilePath ) , '/-/deno.land/x/aleph/aleph.js' ) ) } ;` ,
815
+ `export default function MarkdownPage() {` ,
816
+ this . isDev && ` _s();` ,
817
+ ` const ref = useRef(null);` ,
818
+ ` useEffect(() => {` ,
819
+ ` const appLinks = [];` ,
820
+ ` const onClick = e => {` ,
821
+ ` e.preventDefault();` ,
822
+ ` redirect(e.target.getAttribute("href"));` ,
823
+ ` };` ,
824
+ ` if (ref.current) {` ,
825
+ ` ref.current.querySelectorAll("a").forEach(a => {` ,
826
+ ` if (!/^(https?|mailto|file):/i.test(a.getAttribute("href"))) {` ,
827
+ ` a.addEventListener("click", onClick);` ,
828
+ ` appLinks.push(a);` ,
829
+ ` }` ,
830
+ ` });` ,
831
+ ` }` ,
832
+ ` return () => appLinks.forEach(a => a.removeEventListener("click", onClick));` ,
833
+ ` }, [])` ,
834
+ ` return React.createElement("div", {className: "markdown-page", ref, dangerouslySetInnerHTML: {__html: ${ JSON . stringify ( html ) } }});` ,
822
835
`}` ,
823
- `Markdown.meta = ${ JSON . stringify ( props , undefined , this . isDev ? 4 : undefined ) } ;` ,
824
- this . isDev && `$RefreshReg$(Markdown, "Markdown");` ,
836
+ `MarkdownPage.meta = ${ JSON . stringify ( props , undefined , this . isDev ? 4 : undefined ) } ;` ,
837
+ this . isDev && `_s(MarkdownPage, "useRef{ref}\\nuseEffect{}");` ,
838
+ this . isDev && `$RefreshReg$(MarkdownPage, "MarkdownPage");` ,
825
839
] . filter ( Boolean ) . join ( this . isDev ? '\n' : '' )
826
840
mod . jsSourceMap = ''
827
841
mod . hash = ( new Sha1 ) . update ( mod . jsContent ) . hex ( )
0 commit comments