-
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.
feat: add tree shakeable manager providers [skip release] (#1004)
* refactor: turn Open Graph providers into tree-shakeable ones * refactor: turn Open Graph profile providers into tree-shakeable * refactor: turn JSON-LD providers into tree-shakeable ones Also: - Move types to the `types` directory - Rename provider to make it a bit more specific * refactor: turn standard providers into tree-shakeable ones * refactor: turn Twitter Card providers into tree-shakeable ones * refactor: rename provide json-ld file * refactor: hide JSON-LD provider * feat: add pure but deprecated Open Graph const providers * feat: add pure but deprecated Open Graph profile const providers * feat: add pure but deprecated JSON-LD const provider * feat: add pure but deprecated standard const providers * feat: add pure but deprecated Twitter Card const providers
- Loading branch information
Showing
80 changed files
with
1,183 additions
and
770 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './src/managers' | ||
export * from './src/types' | ||
export * from './src/providers' |
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,2 +1 @@ | ||
export { JsonLdMetadata } from './json-ld-metadata' | ||
export { JSON_LD_METADATA_PROVIDER } from './json-ld-metadata-provider' | ||
export { JSON_LD_METADATA_PROVIDER } from './provide-json-ld-in-head' |
34 changes: 0 additions & 34 deletions
34
projects/ngx-meta/src/json-ld/src/managers/json-ld-metadata-provider.ts
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
projects/ngx-meta/src/json-ld/src/managers/provide-json-ld-in-head.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,44 @@ | ||
import { DOCUMENT } from '@angular/common' | ||
import { | ||
_headElementUpsertOrRemove, | ||
_HeadElementUpsertOrRemove, | ||
_isDefined, | ||
provideNgxMetaManager, | ||
withManagerDeps, | ||
withOptions, | ||
} from '@davidlj95/ngx-meta/core' | ||
import { JsonLdMetadata } from '../types' | ||
|
||
const SCRIPT_TYPE = 'application/ld+json' | ||
|
||
/** | ||
* Manages the {@link JsonLdMetadata.jsonLd} metadata by placing it into the page's `<head>` | ||
* @public | ||
*/ | ||
export const provideJsonLdInHead = () => | ||
provideNgxMetaManager<JsonLdMetadata['jsonLd']>( | ||
'jsonLd' satisfies keyof JsonLdMetadata, | ||
(headElementUpsertOrRemove: _HeadElementUpsertOrRemove, doc: Document) => | ||
(jsonLd) => { | ||
let scriptElement: HTMLScriptElement | undefined | ||
if (_isDefined(jsonLd)) { | ||
scriptElement = doc.createElement('script') | ||
scriptElement.setAttribute('type', SCRIPT_TYPE) | ||
scriptElement.innerHTML = JSON.stringify(jsonLd) | ||
} | ||
headElementUpsertOrRemove( | ||
`script[type='${SCRIPT_TYPE}']`, | ||
scriptElement, | ||
) | ||
}, | ||
withOptions(withManagerDeps(_headElementUpsertOrRemove(), DOCUMENT)), | ||
) | ||
|
||
/** | ||
* {@inheritDoc provideNgxMetaJsonLd} | ||
* @deprecated Use {@link provideNgxMetaJsonLd} instead | ||
* @public | ||
*/ | ||
export const JSON_LD_METADATA_PROVIDER = | ||
/* @__PURE__ */ | ||
provideJsonLdInHead() |
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 { JsonLdMetadata } from './json-ld-metadata' |
Oops, something went wrong.