-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: reduce Open Graph module bundle size (#150)
* perf: reduce Open Graph module bundle size * refactor: reorder og imports in provider
- Loading branch information
Showing
30 changed files
with
291 additions
and
310 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,8 @@ | |
"commitlint-last": "commitlint --verbose --from HEAD~1", | ||
"generate-prettier-ignore": "cp .gitignore .prettierignore && cat .part.prettierignore >> .prettierignore", | ||
"semantic-release": "semantic-release", | ||
"ng-lint-staged": "ng-lint-staged lint --max-warnings 0 --fix --" | ||
"ng-lint-staged": "ng-lint-staged lint --max-warnings 0 --fix --", | ||
"cache-clean": "ng cache clean" | ||
}, | ||
"private": true, | ||
"packageManager": "[email protected]", | ||
|
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 @@ | ||
export type MetadataSetter<T> = (value: T) => void |
32 changes: 32 additions & 0 deletions
32
projects/ngx-meta/src/core/src/provide-metadata-factory.ts
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,32 @@ | ||
import { Metadata } from './metadata' | ||
import { FactoryProvider } from '@angular/core' | ||
import { MetadataDefinition } from './metadata-definition' | ||
import { MetadataSetter } from './metadata-setter' | ||
|
||
export type MetadataSetterFactory<T> = ( | ||
...deps: Exclude<FactoryProvider['deps'], undefined> | ||
) => MetadataSetter<T> | ||
|
||
const makeMetadata = <T>( | ||
definition: MetadataDefinition, | ||
set: MetadataSetter<T>, | ||
): Metadata<T> => { | ||
return { | ||
definition, | ||
set, | ||
} | ||
} | ||
|
||
export function provideMetadataFactory<T>( | ||
definition: MetadataDefinition, | ||
setterFactory: MetadataSetterFactory<T>, | ||
deps?: FactoryProvider['deps'], | ||
): FactoryProvider { | ||
return { | ||
provide: Metadata, | ||
multi: true, | ||
useFactory: (...deps: unknown[]) => | ||
makeMetadata(definition, setterFactory(...deps)), | ||
deps, | ||
} | ||
} |
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
8 changes: 4 additions & 4 deletions
8
projects/ngx-meta/src/open-graph-profile/src/open-graph-profile-metadata-route-data.ts
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
export { OpenGraphModule as NgxMetaOpenGraphModule } from './src/open-graph.module' | ||
export { provideOpenGraph as provideNgxMetaOpenGraphMetadata } from './src/provide-open-graph' | ||
export * from './src/open-graph' | ||
export * from './src/open-graph-image' | ||
export * from './src/open-graph-meta-property' | ||
export * from './src/open-graph-metadata-route-data' | ||
export * from './src/open-graph-metadata' | ||
export * from './src/open-graph-type' | ||
// Specific metadata | ||
export * from './src/title-open-graph-metadata' | ||
export * from './src/type-open-graph-metadata' | ||
export * from './src/image-open-graph-metadata' | ||
export * from './src/url-open-graph-metadata' | ||
export * from './src/description-open-graph-metadata' | ||
export * from './src/locale-open-graph-metadata' | ||
export * from './src/site-name-open-graph-metadata' | ||
// Providers | ||
export * from './src/open-graph-title-metadata-provider' | ||
export * from './src/open-graph-type-metadata-provider' | ||
export * from './src/open-graph-image-metadata-provider' | ||
export * from './src/open-graph-url-metadata-provider' | ||
export * from './src/open-graph-description-metadata-provider' | ||
export * from './src/open-graph-locale-metadata-provider' | ||
export * from './src/open-graph-site-name-metadata-provider' |
17 changes: 0 additions & 17 deletions
17
projects/ngx-meta/src/open-graph/src/base-open-graph-metadata.ts
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
projects/ngx-meta/src/open-graph/src/description-open-graph-metadata.ts
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
projects/ngx-meta/src/open-graph/src/image-open-graph-metadata.ts
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
projects/ngx-meta/src/open-graph/src/locale-open-graph-metadata.ts
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
projects/ngx-meta/src/open-graph/src/make-open-graph-metadata-provider.ts
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,32 @@ | ||
import { | ||
GlobalMetadataKey, | ||
MetadataSetterFactory, | ||
MetaService, | ||
provideMetadataFactory, | ||
StringKeyOf, | ||
} from '@davidlj95/ngx-meta/core' | ||
import { OpenGraph } from './open-graph' | ||
import { FactoryProvider } from '@angular/core' | ||
import { OpenGraphMetadataDefinition } from './open-graph-metadata-definition' | ||
import { OpenGraphMetaProperty } from './open-graph-meta-property' | ||
|
||
export const makeOpenGraphMetadataProvider = < | ||
Key extends StringKeyOf<OpenGraph>, | ||
>( | ||
key: Key, | ||
opts: { | ||
// Open Graph property name. Defaults to key | ||
p?: string | ||
// Global key. Defaults to nothing | ||
g?: GlobalMetadataKey | ||
// Setter factory. Defaults to setting the property to the given value. | ||
s?: MetadataSetterFactory<OpenGraph[typeof key]> | ||
} = {}, | ||
): FactoryProvider => | ||
provideMetadataFactory( | ||
new OpenGraphMetadataDefinition(key, opts.g), | ||
opts.s ?? | ||
((metaService) => (value: OpenGraph[typeof key]) => | ||
metaService.set(new OpenGraphMetaProperty(opts.p ?? key), value)), | ||
[MetaService], | ||
) |
7 changes: 7 additions & 0 deletions
7
projects/ngx-meta/src/open-graph/src/open-graph-description-metadata-provider.ts
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,7 @@ | ||
import { makeOpenGraphMetadataProvider } from './make-open-graph-metadata-provider' | ||
import { OpenGraph } from './open-graph' | ||
|
||
const KEY: keyof OpenGraph = 'description' | ||
|
||
export const OPEN_GRAPH_DESCRIPTION_METADATA_PROVIDER = | ||
makeOpenGraphMetadataProvider(KEY, { g: KEY }) |
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
43 changes: 43 additions & 0 deletions
43
projects/ngx-meta/src/open-graph/src/open-graph-image-metadata-provider.ts
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,43 @@ | ||
import { OpenGraph } from './open-graph' | ||
import { MetaService } from '@davidlj95/ngx-meta/core' | ||
import { OpenGraphMetaProperty } from './open-graph-meta-property' | ||
import { makeOpenGraphMetadataProvider } from './make-open-graph-metadata-provider' | ||
|
||
const KEY: keyof OpenGraph = 'image' | ||
const NO_KEY_VALUE: OpenGraph[typeof KEY] = { | ||
url: undefined, | ||
alt: undefined, | ||
secureUrl: null, | ||
type: null, | ||
width: null, | ||
height: null, | ||
} | ||
|
||
export const OPEN_GRAPH_IMAGE_SETTER_FACTORY = | ||
(metaService: MetaService) => (value: OpenGraph[typeof KEY]) => { | ||
const imageUrl = value?.url?.toString() | ||
const effectiveValue: OpenGraph[typeof KEY] = | ||
imageUrl !== undefined && imageUrl !== null ? value : NO_KEY_VALUE | ||
metaService.set(new OpenGraphMetaProperty(KEY), imageUrl) | ||
metaService.set(new OpenGraphMetaProperty(KEY, 'alt'), effectiveValue?.alt) | ||
metaService.set( | ||
new OpenGraphMetaProperty(KEY, 'secure_url'), | ||
effectiveValue?.secureUrl?.toString(), | ||
) | ||
metaService.set( | ||
new OpenGraphMetaProperty(KEY, 'type'), | ||
effectiveValue?.type, | ||
) | ||
metaService.set( | ||
new OpenGraphMetaProperty(KEY, 'width'), | ||
effectiveValue?.width?.toString(), | ||
) | ||
metaService.set( | ||
new OpenGraphMetaProperty(KEY, 'height'), | ||
effectiveValue?.height?.toString(), | ||
) | ||
} | ||
export const OPEN_GRAPH_IMAGE_METADATA_PROVIDER = makeOpenGraphMetadataProvider( | ||
KEY, | ||
{ s: OPEN_GRAPH_IMAGE_SETTER_FACTORY, g: KEY }, | ||
) |
6 changes: 6 additions & 0 deletions
6
projects/ngx-meta/src/open-graph/src/open-graph-locale-metadata-provider.ts
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 { makeOpenGraphMetadataProvider } from './make-open-graph-metadata-provider' | ||
import { OpenGraph } from './open-graph' | ||
|
||
const key: keyof OpenGraph = 'locale' | ||
export const OPEN_GRAPH_LOCALE_METADATA_PROVIDER = | ||
makeOpenGraphMetadataProvider(key, { g: key }) |
10 changes: 10 additions & 0 deletions
10
projects/ngx-meta/src/open-graph/src/open-graph-metadata-definition.ts
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 { ScopedMetadataDefinition } from '@davidlj95/ngx-meta/core' | ||
import { OpenGraphMetadata } from './open-graph-metadata' | ||
|
||
const SCOPE: keyof OpenGraphMetadata = 'openGraph' | ||
|
||
export class OpenGraphMetadataDefinition extends ScopedMetadataDefinition { | ||
constructor(name: string, global?: string) { | ||
super(SCOPE, name, global) | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
projects/ngx-meta/src/open-graph/src/open-graph-metadata-route-data.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.