-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(fonts): config #12777
Merged
Merged
feat(fonts): config #12777
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7491475
feat(fonts): config
florian-lefebvre f9705a0
feat: improve
florian-lefebvre 5ab9fe5
feat: work on generics
florian-lefebvre a5e9435
Merge branch 'feat/fonts' into feat/fonts-config
florian-lefebvre 2561022
fix: types
florian-lefebvre d2f5827
feat: clean types
florian-lefebvre 52a1d05
chore: remove todos
florian-lefebvre 139300f
feat: work on types tests
florian-lefebvre d372335
feat: work on types tests
florian-lefebvre 1dfdbde
feat: config tests
florian-lefebvre 3a4dc3f
feat: better error
florian-lefebvre 7e6ba0f
Merge branch 'feat/fonts' into feat/fonts-config
florian-lefebvre c79ed01
feat: export type
florian-lefebvre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { GOOGLE_PROVIDER_NAME } from "./providers/google.js"; | ||
import { LOCAL_PROVIDER_NAME } from "./providers/local.js"; | ||
|
||
export const BUILTIN_PROVIDERS = [GOOGLE_PROVIDER_NAME, LOCAL_PROVIDER_NAME] as const; |
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,5 @@ | ||
import type { FontProvider } from './types.js'; | ||
|
||
export function defineFontProvider<TName extends string>(provider: FontProvider<TName>) { | ||
return provider; | ||
} |
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,6 @@ | ||
import { adobe } from './providers/adobe.js'; | ||
|
||
/** TODO: */ | ||
export const fontProviders = { | ||
adobe, | ||
}; |
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,9 @@ | ||
import { defineFontProvider } from '../helpers.js'; | ||
|
||
export function adobe(config: { apiKey: string }) { | ||
return defineFontProvider({ | ||
name: 'adobe', | ||
entrypoint: 'astro/assets/fonts/providers/adobe', | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineFontProvider } from '../helpers.js'; | ||
|
||
export const GOOGLE_PROVIDER_NAME = 'google'; | ||
|
||
export function google() { | ||
return defineFontProvider({ | ||
name: GOOGLE_PROVIDER_NAME, | ||
entrypoint: 'astro/assets/fonts/providers/google', | ||
ematipico marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} |
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,10 @@ | ||
import { defineFontProvider } from '../helpers.js'; | ||
|
||
export const LOCAL_PROVIDER_NAME = 'local'; | ||
|
||
export function local() { | ||
return defineFontProvider({ | ||
name: LOCAL_PROVIDER_NAME, | ||
entrypoint: 'astro/assets/fonts/providers/google', | ||
}); | ||
} |
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,27 @@ | ||
import type { BUILTIN_PROVIDERS } from './constants.js'; | ||
import type { GOOGLE_PROVIDER_NAME } from './providers/google.js'; | ||
import type { LOCAL_PROVIDER_NAME } from './providers/local.js'; | ||
|
||
export interface FontProvider<TName extends string> { | ||
name: TName; | ||
entrypoint: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll address this in the next PR |
||
config?: Record<string, any>; | ||
} | ||
|
||
type LocalFontFamily = { | ||
provider: LocalProviderName; | ||
// TODO: refine type | ||
src: string; | ||
}; | ||
|
||
type StandardFontFamily<TProvider extends string> = { | ||
provider: TProvider; | ||
}; | ||
|
||
export type FontFamily<TProvider extends string> = TProvider extends LocalProviderName | ||
? LocalFontFamily | ||
: StandardFontFamily<TProvider>; | ||
|
||
export type LocalProviderName = typeof LOCAL_PROVIDER_NAME; | ||
export type GoogleProviderName = typeof GOOGLE_PROVIDER_NAME; | ||
export type BuiltInProvider = (typeof BUILTIN_PROVIDERS)[number]; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entrypoints should have the file extension. E.g.
astro/assets/fonts/providers/adobe.js