-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from AElfProject/feature/next-export-optimize-…
…images feat: build time export of images
- Loading branch information
Showing
14 changed files
with
795 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Dark, Light } from "./theme"; | ||
import CustomImage from "../customImage"; | ||
|
||
interface Props { | ||
baseConfig: { [key: string]: any }; | ||
className?: string; | ||
theme?: string; | ||
} | ||
export function Logo({ baseConfig, className }: Props) { | ||
return ( | ||
<> | ||
{baseConfig?.logoLight ? ( | ||
<Light> | ||
<CustomImage | ||
src={baseConfig.logoLight} | ||
width={115} | ||
height={32} | ||
alt="logo" | ||
className={className} | ||
/> | ||
</Light> | ||
) : null} | ||
{baseConfig?.logoDark ? ( | ||
<Dark> | ||
<CustomImage | ||
src={baseConfig.logoLight} | ||
width={115} | ||
height={32} | ||
alt="logo" | ||
className={className} | ||
/> | ||
</Dark> | ||
) : null} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import CustomImage from "@/components/customImage"; | ||
|
||
interface Props { | ||
src: string; | ||
className?: string; | ||
} | ||
export function SsrLogo({ src, className }: Props) { | ||
return ( | ||
<CustomImage | ||
src={src} | ||
width={115} | ||
height={32} | ||
alt="logo" | ||
className={className} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use client"; | ||
|
||
import { useTheme } from "next-themes"; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
} | ||
|
||
export function Light({ children }: Props) { | ||
const { resolvedTheme } = useTheme(); | ||
|
||
if (resolvedTheme === "light") return <>{children}</>; | ||
} | ||
|
||
export function Dark({ children }: Props) { | ||
const { resolvedTheme } = useTheme(); | ||
|
||
if (resolvedTheme !== "light") return <>{children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @type {import('next-export-optimize-images').Config} | ||
*/ | ||
const config = { | ||
filenameGenerator: ({ path, name, width, extension }) => | ||
`${name}.${width}.${extension}`, | ||
sourceImageParser: ({ src, defaultParser }) => { | ||
const regExpMatches = src.match(/^.*\?code=(.*)$/); | ||
if (!regExpMatches) { | ||
return defaultParser(src); | ||
} | ||
|
||
// if the src has fileId and extension in its route then it | ||
// must be a non-standard image, so parse it differently for all intents | ||
// and purposes | ||
return { | ||
pathWithoutName: "", // maybe there is no path, or you can supply an arbitrary one for filename processing | ||
name: regExpMatches[1] || "", | ||
extension: "png", | ||
}; | ||
}, | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.