@unhead/addons 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @unhead/addons
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ # yarn add @unhead/addons
7
+ npm install @unhead/addons
8
+ ```
9
+
10
+ ## Documentation
11
+
12
+ See the [unhead](https://unhead.harlanzw.com/) for more details.
package/dist/index.cjs ADDED
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ const unhead = require('unhead');
4
+
5
+ const InferSeoMetaPlugin = (options) => unhead.defineHeadPlugin({
6
+ hooks: {
7
+ tags: {
8
+ resolve(ctx) {
9
+ const title = ctx.tags.find((t) => t.tag === "title" && !!t.children);
10
+ if (title) {
11
+ ctx.tags.push({
12
+ _e: title._e,
13
+ tag: "meta",
14
+ props: {
15
+ property: "og:title",
16
+ content: options?.ogTitle ? options.ogTitle(title.children) : title.children
17
+ }
18
+ });
19
+ }
20
+ const description = ctx.tags.find((t) => t.tag === "meta" && t.props.name === "description" && !!t.props.content);
21
+ if (description) {
22
+ ctx.tags.push({
23
+ _e: description._e,
24
+ tag: "meta",
25
+ props: {
26
+ name: "og:description",
27
+ content: options?.ogDescription ? options.ogDescription(description.props.content) : description.props.content
28
+ }
29
+ });
30
+ }
31
+ const ogImage = ctx.tags.find((t) => t.tag === "meta" && t.props.property === "og:image");
32
+ if (ogImage && !ctx.tags.find((t) => t.tag === "meta" && t.props.property === "twitter:card")) {
33
+ ctx.tags.push({
34
+ _e: ogImage._e,
35
+ tag: "meta",
36
+ props: {
37
+ property: "twitter:card",
38
+ content: options?.twitterCard || "summary_large_image"
39
+ }
40
+ });
41
+ }
42
+ if (options?.robots && !ctx.tags.find((t) => t.tag === "meta" && t.props.name === "robots")) {
43
+ ctx.tags.push({
44
+ _e: ctx.tags[0]._e,
45
+ tag: "meta",
46
+ props: {
47
+ name: "robots",
48
+ content: "max-snippet: -1; max-image-preview: large; max-video-preview: -1"
49
+ }
50
+ });
51
+ }
52
+ }
53
+ }
54
+ }
55
+ });
56
+
57
+ const DefaultCriticalTags = {
58
+ htmlAttrs: {
59
+ lang: "en"
60
+ },
61
+ meta: [
62
+ { charset: "utf-8" },
63
+ { name: "viewport", content: "width=device-width, initial-scale=1" }
64
+ ]
65
+ };
66
+
67
+ exports.DefaultCriticalTags = DefaultCriticalTags;
68
+ exports.InferSeoMetaPlugin = InferSeoMetaPlugin;
@@ -0,0 +1,46 @@
1
+ import * as _unhead_schema from '@unhead/schema';
2
+
3
+ interface InferSeoMetaPluginOptions {
4
+ /**
5
+ * Transform the og title.
6
+ *
7
+ * @param title
8
+ */
9
+ ogTitle?: (title: string) => string;
10
+ /**
11
+ * Transform the og description.
12
+ *
13
+ * @param title
14
+ */
15
+ ogDescription?: (description: string) => string;
16
+ /**
17
+ * Whether robot meta should be infered.
18
+ *
19
+ * @default true
20
+ */
21
+ robots?: boolean;
22
+ /**
23
+ * The twitter card to use.
24
+ *
25
+ * @default 'summary_large_image'
26
+ */
27
+ twitterCard?: string;
28
+ }
29
+ declare const InferSeoMetaPlugin: (options?: InferSeoMetaPluginOptions) => _unhead_schema.HeadPlugin;
30
+
31
+ declare const DefaultCriticalTags: {
32
+ htmlAttrs: {
33
+ lang: string;
34
+ };
35
+ meta: ({
36
+ charset: string;
37
+ name?: undefined;
38
+ content?: undefined;
39
+ } | {
40
+ name: string;
41
+ content: string;
42
+ charset?: undefined;
43
+ })[];
44
+ };
45
+
46
+ export { DefaultCriticalTags, InferSeoMetaPlugin, InferSeoMetaPluginOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,65 @@
1
+ import { defineHeadPlugin } from 'unhead';
2
+
3
+ const InferSeoMetaPlugin = (options) => defineHeadPlugin({
4
+ hooks: {
5
+ tags: {
6
+ resolve(ctx) {
7
+ const title = ctx.tags.find((t) => t.tag === "title" && !!t.children);
8
+ if (title) {
9
+ ctx.tags.push({
10
+ _e: title._e,
11
+ tag: "meta",
12
+ props: {
13
+ property: "og:title",
14
+ content: options?.ogTitle ? options.ogTitle(title.children) : title.children
15
+ }
16
+ });
17
+ }
18
+ const description = ctx.tags.find((t) => t.tag === "meta" && t.props.name === "description" && !!t.props.content);
19
+ if (description) {
20
+ ctx.tags.push({
21
+ _e: description._e,
22
+ tag: "meta",
23
+ props: {
24
+ name: "og:description",
25
+ content: options?.ogDescription ? options.ogDescription(description.props.content) : description.props.content
26
+ }
27
+ });
28
+ }
29
+ const ogImage = ctx.tags.find((t) => t.tag === "meta" && t.props.property === "og:image");
30
+ if (ogImage && !ctx.tags.find((t) => t.tag === "meta" && t.props.property === "twitter:card")) {
31
+ ctx.tags.push({
32
+ _e: ogImage._e,
33
+ tag: "meta",
34
+ props: {
35
+ property: "twitter:card",
36
+ content: options?.twitterCard || "summary_large_image"
37
+ }
38
+ });
39
+ }
40
+ if (options?.robots && !ctx.tags.find((t) => t.tag === "meta" && t.props.name === "robots")) {
41
+ ctx.tags.push({
42
+ _e: ctx.tags[0]._e,
43
+ tag: "meta",
44
+ props: {
45
+ name: "robots",
46
+ content: "max-snippet: -1; max-image-preview: large; max-video-preview: -1"
47
+ }
48
+ });
49
+ }
50
+ }
51
+ }
52
+ }
53
+ });
54
+
55
+ const DefaultCriticalTags = {
56
+ htmlAttrs: {
57
+ lang: "en"
58
+ },
59
+ meta: [
60
+ { charset: "utf-8" },
61
+ { name: "viewport", content: "width=device-width, initial-scale=1" }
62
+ ]
63
+ };
64
+
65
+ export { DefaultCriticalTags, InferSeoMetaPlugin };
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ const unplugin = require('unplugin');
4
+ const pluginutils = require('@rollup/pluginutils');
5
+ const unpluginAst = require('unplugin-ast');
6
+
7
+ const RemoveFunctions = (functionNames) => ({
8
+ onNode: (node) => node.type === "CallExpression" && node.callee.type === "Identifier" && functionNames.includes(node.callee.name),
9
+ transform() {
10
+ return false;
11
+ }
12
+ });
13
+ const TreeshakeServerComposables = unplugin.createUnplugin((userConfig = {}) => {
14
+ const filter = pluginutils.createFilter([
15
+ /\.[jt]sx?$/,
16
+ /\.vue$/
17
+ ], [
18
+ "node_modules"
19
+ ]);
20
+ let root = userConfig.root;
21
+ return {
22
+ name: "unhead:remove-server-composables",
23
+ enforce: "post",
24
+ transformInclude(id) {
25
+ if (root && !id.startsWith(root))
26
+ return false;
27
+ if (!filter(id))
28
+ return false;
29
+ },
30
+ async transform(code, id) {
31
+ if (!code.includes("useServerHead") && !code.includes("useSeoMeta")) {
32
+ return null;
33
+ }
34
+ let transformed;
35
+ try {
36
+ transformed = await unpluginAst.transform(code, id, {
37
+ parserOptions: {},
38
+ transformer: [
39
+ RemoveFunctions([
40
+ "useServerHead",
41
+ "useSeoMeta"
42
+ ])
43
+ ]
44
+ });
45
+ } catch (e) {
46
+ }
47
+ return transformed;
48
+ },
49
+ vite: {
50
+ async config(config) {
51
+ root = root || config.root || process.cwd();
52
+ }
53
+ }
54
+ };
55
+ });
56
+
57
+ exports.TreeshakeServerComposables = TreeshakeServerComposables;
@@ -0,0 +1,55 @@
1
+ import { createUnplugin } from 'unplugin';
2
+ import { createFilter } from '@rollup/pluginutils';
3
+ import { transform } from 'unplugin-ast';
4
+
5
+ const RemoveFunctions = (functionNames) => ({
6
+ onNode: (node) => node.type === "CallExpression" && node.callee.type === "Identifier" && functionNames.includes(node.callee.name),
7
+ transform() {
8
+ return false;
9
+ }
10
+ });
11
+ const TreeshakeServerComposables = createUnplugin((userConfig = {}) => {
12
+ const filter = createFilter([
13
+ /\.[jt]sx?$/,
14
+ /\.vue$/
15
+ ], [
16
+ "node_modules"
17
+ ]);
18
+ let root = userConfig.root;
19
+ return {
20
+ name: "unhead:remove-server-composables",
21
+ enforce: "post",
22
+ transformInclude(id) {
23
+ if (root && !id.startsWith(root))
24
+ return false;
25
+ if (!filter(id))
26
+ return false;
27
+ },
28
+ async transform(code, id) {
29
+ if (!code.includes("useServerHead") && !code.includes("useSeoMeta")) {
30
+ return null;
31
+ }
32
+ let transformed;
33
+ try {
34
+ transformed = await transform(code, id, {
35
+ parserOptions: {},
36
+ transformer: [
37
+ RemoveFunctions([
38
+ "useServerHead",
39
+ "useSeoMeta"
40
+ ])
41
+ ]
42
+ });
43
+ } catch (e) {
44
+ }
45
+ return transformed;
46
+ },
47
+ vite: {
48
+ async config(config) {
49
+ root = root || config.root || process.cwd();
50
+ }
51
+ }
52
+ };
53
+ });
54
+
55
+ export { TreeshakeServerComposables as T };
@@ -0,0 +1,8 @@
1
+ interface PluginOptions {
2
+ /**
3
+ * Root directory
4
+ */
5
+ root?: string;
6
+ }
7
+
8
+ export { PluginOptions as P };
package/dist/vite.cjs ADDED
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const TreeshakeServerComposables = require('./shared/addons.8476d2f2.cjs');
4
+ require('unplugin');
5
+ require('@rollup/pluginutils');
6
+ require('unplugin-ast');
7
+
8
+ const vite = (args = {}) => {
9
+ return [
10
+ TreeshakeServerComposables.TreeshakeServerComposables.vite(args)
11
+ ];
12
+ };
13
+
14
+ module.exports = vite;
package/dist/vite.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import * as vite from 'vite';
2
+ import { P as PluginOptions } from './types-3ec0a9ee.js';
3
+
4
+ declare const _default: (args?: PluginOptions) => vite.Plugin[];
5
+
6
+ export { _default as default };
package/dist/vite.mjs ADDED
@@ -0,0 +1,12 @@
1
+ import { T as TreeshakeServerComposables } from './shared/addons.f55513ea.mjs';
2
+ import 'unplugin';
3
+ import '@rollup/pluginutils';
4
+ import 'unplugin-ast';
5
+
6
+ const vite = (args = {}) => {
7
+ return [
8
+ TreeshakeServerComposables.vite(args)
9
+ ];
10
+ };
11
+
12
+ export { vite as default };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const TreeshakeServerComposables = require('./shared/addons.8476d2f2.cjs');
4
+ require('unplugin');
5
+ require('@rollup/pluginutils');
6
+ require('unplugin-ast');
7
+
8
+ const webpack = (args = {}) => {
9
+ return [
10
+ TreeshakeServerComposables.TreeshakeServerComposables.webpack(args)
11
+ ];
12
+ };
13
+
14
+ module.exports = webpack;
@@ -0,0 +1,6 @@
1
+ import * as webpack from 'webpack';
2
+ import { P as PluginOptions } from './types-3ec0a9ee.js';
3
+
4
+ declare const _default: (args?: PluginOptions) => webpack.WebpackPluginInstance[];
5
+
6
+ export { _default as default };
@@ -0,0 +1,12 @@
1
+ import { T as TreeshakeServerComposables } from './shared/addons.f55513ea.mjs';
2
+ import 'unplugin';
3
+ import '@rollup/pluginutils';
4
+ import 'unplugin-ast';
5
+
6
+ const webpack = (args = {}) => {
7
+ return [
8
+ TreeshakeServerComposables.webpack(args)
9
+ ];
10
+ };
11
+
12
+ export { webpack as default };
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@unhead/addons",
3
+ "type": "module",
4
+ "version": "0.6.8",
5
+ "packageManager": "pnpm@7.14.0",
6
+ "author": "Harlan Wilton <harlan@harlanzw.com>",
7
+ "license": "MIT",
8
+ "funding": "https://github.com/sponsors/harlan-zw",
9
+ "homepage": "https://github.com/harlan-zw/unhead#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/harlan-zw/unhead.git",
13
+ "directory": "packages/ssr"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/harlan-zw/unhead/issues"
17
+ },
18
+ "sideEffects": false,
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "require": "./dist/index.cjs",
23
+ "import": "./dist/index.mjs"
24
+ },
25
+ "./vite": {
26
+ "types": "./dist/vite.d.ts",
27
+ "require": "./dist/vite.cjs",
28
+ "import": "./dist/vite.mjs"
29
+ },
30
+ "./webpack": {
31
+ "types": "./dist/webpack.d.ts",
32
+ "require": "./dist/webpack.cjs",
33
+ "import": "./dist/webpack.mjs"
34
+ }
35
+ },
36
+ "typesVersions": {
37
+ "*": {
38
+ "vite": [
39
+ "dist/vite.d.ts"
40
+ ],
41
+ "webpack": [
42
+ "dist/webpack.d.ts"
43
+ ]
44
+ }
45
+ },
46
+ "main": "dist/index.cjs",
47
+ "module": "dist/index.mjs",
48
+ "types": "dist/index.d.ts",
49
+ "files": [
50
+ "dist"
51
+ ],
52
+ "dependencies": {
53
+ "unhead": "0.6.8",
54
+ "@rollup/pluginutils": "^5.0.2",
55
+ "@unhead/schema": "0.6.8",
56
+ "unplugin": "^1.0.0",
57
+ "unplugin-ast": "^0.5.5"
58
+ },
59
+ "devDependencies": {
60
+ "@babel/types": "^7.20.2",
61
+ "zhead": "1.0.0-beta.13"
62
+ },
63
+ "scripts": {
64
+ "build": "unbuild .",
65
+ "stub": "unbuild . --stub",
66
+ "export:sizes": "npx export-size . -r"
67
+ }
68
+ }