astro-link-card 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 roboin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # astro-link-card
2
+
3
+ Astro integration to automatically convert bare links into link cards. This is a wrapper for [rehype-og-card](https://github.com/Robot-Inventor/rehype-og-card) with some configuration optimizations for Astro.
4
+
5
+ ## Features
6
+
7
+ This integration will automatically convert bare links into link cards. This is useful for creating a more visually appealing website with link previews. Here are some key features:
8
+
9
+ - Automatically convert bare links into link cards
10
+ - Server-side image caching
11
+ - Build cache for images and Open Graph metadata for faster builds
12
+ - Lazy loading and async decoding for images
13
+ - Zero runtime JavaScript (all processing is done at build time)
14
+
15
+ The following links will be converted to link cards:
16
+
17
+ - Bare links
18
+ - Links that have the same URL and text (if you enable the `enableSameTextURLConversion` option)
19
+
20
+ The following links will NOT be converted to link cards:
21
+
22
+ - Links in lists
23
+ - Links in code blocks
24
+ - Links in sentences
25
+ - Non-bare links
26
+ - Links that have the same URL and text (if you disable the enableSameTextURLConversion option)
27
+
28
+ Input:
29
+
30
+ ```markdown
31
+ this is a link: https://blog.google/products/android/world-emoji-day-2024/
32
+
33
+ \`https://blog.google/products/android/world-emoji-day-2024/\`
34
+
35
+ https://blog.google/products/android/world-emoji-day-2024/
36
+ ```
37
+
38
+ Output (formatted for readability):
39
+
40
+ ```html
41
+ <p>this is a link: https://blog.google/products/android/world-emoji-day-2024/</p>
42
+ <p><code>https://blog.google/products/android/world-emoji-day-2024/</code></p>
43
+ <p><div class="og-card-container">
44
+ <a href="https://blog.google/products/android/world-emoji-day-2024/">
45
+ <div class="og-card-info">
46
+ <div class="og-card-title">10 fun facts about emoji for World Emoji Day</div>
47
+ <div class="og-card-description">Celebrate World Emoji Day with Google, and check out what’s new for Emoji Kitchen.</div>
48
+ <div class="og-card-url-container">
49
+ <img class="og-card-favicon" alt="favicon" decoding="async" height="16" loading="lazy" src="https://www.google.com/s2/favicons?domain=blog.google" width="16">
50
+ <span class="og-card-url">blog.google</span>
51
+ </div>
52
+ </div>
53
+ <div class="og-card-image-container">
54
+ <img class="og-card-image" alt="https://storage.googleapis.com/gweb-uniblog-publish-prod/images/world_emoji_day_v2_1.width-1300.png" decoding="async" loading="lazy" src="https://storage.googleapis.com/gweb-uniblog-publish-prod/images/world_emoji_day_v2_1.width-1300.png">
55
+ </div>
56
+ </a>
57
+ </div></p>
58
+ ```
59
+
60
+ ## Installation
61
+
62
+ ### `astro add` command (Recommended)
63
+
64
+ ```bash
65
+ npx astro add astro-link-card
66
+ ```
67
+
68
+ ### Manual Installation (Alternative)
69
+
70
+ ```bash
71
+ npm install astro-link-card
72
+ ```
73
+
74
+ ```typescript
75
+ import { defineConfig } from "astro";
76
+ import linkCard from "astro-link-card";
77
+
78
+ // https://astro.build/config
79
+ export default defineConfig({
80
+ // ... other config
81
+ integrations: [
82
+ [
83
+ linkCard,
84
+ {
85
+ // Options
86
+ }
87
+ ]
88
+ ]
89
+ });
90
+ ```
91
+
92
+ ## Options
93
+
94
+ All rehype-og-card options are supported. You can find the full list of options [here](https://github.com/Robot-Inventor/rehype-og-card?tab=readme-ov-file#options). Some options below are optimized for Astro:
95
+
96
+ - `enableSameTextURLConversion` (default: `true`): Enable conversion of links that have the same URL and text. This is useful for projects that have `markdown.gfm` enabled.
97
+ - `serverCache` (default: `true`): Enable server-side image caching.
98
+ - `serverCachePath` (default: `config.publicDir`): Path to store server-side image cache.
99
+ - `buildCache` (default: `true`): Enable build cache for images and Open Graph metadata.
100
+ - `buildCachePath` (default: `config.cacheDir`): Path to store build cache.
@@ -0,0 +1,12 @@
1
+ import { RehypeOGCardOptions } from "rehype-og-card";
2
+ import type { AstroIntegration } from "astro";
3
+ /**
4
+ * Astro integration to automatically convert bare links into link cards.
5
+ * This is a wrapper for [rehype-og-card](https://github.com/Robot-Inventor/rehype-og-card)
6
+ * with some configuration optimizations for Astro.
7
+ * @param options Options for the rehype-og-card plugin.
8
+ * @returns Astro integration object.
9
+ */
10
+ declare const astroLinkCard: (options?: RehypeOGCardOptions) => AstroIntegration;
11
+ export default astroLinkCard;
12
+ export { RehypeOGCardOptions as AstroLinkCardOptions };
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ import rehypeOGCard from "rehype-og-card";
2
+ /**
3
+ * Astro integration to automatically convert bare links into link cards.
4
+ * This is a wrapper for [rehype-og-card](https://github.com/Robot-Inventor/rehype-og-card)
5
+ * with some configuration optimizations for Astro.
6
+ * @param options Options for the rehype-og-card plugin.
7
+ * @returns Astro integration object.
8
+ */
9
+ const astroLinkCard = (options) => {
10
+ const integration = {
11
+ hooks: {
12
+ // eslint-disable-next-line jsdoc/require-jsdoc
13
+ "astro:config:setup": ({ config, updateConfig }) => {
14
+ const defaultOptions = {
15
+ buildCache: true,
16
+ buildCachePath: config.cacheDir.pathname,
17
+ enableSameTextURLConversion: true,
18
+ serverCache: true,
19
+ serverCachePath: config.publicDir.pathname
20
+ };
21
+ const mergedOptions = {
22
+ ...defaultOptions,
23
+ ...options
24
+ };
25
+ updateConfig({
26
+ markdown: {
27
+ rehypePlugins: [[rehypeOGCard, mergedOptions]]
28
+ }
29
+ });
30
+ }
31
+ },
32
+ name: "astro-link-card"
33
+ };
34
+ return integration;
35
+ };
36
+ export default astroLinkCard;
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "astro-link-card",
3
+ "version": "0.1.0",
4
+ "description": "Astro integration to automatically convert bare links into link cards.",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "./dist/"
9
+ ],
10
+ "type": "module",
11
+ "publishConfig": {
12
+ "provenance": true
13
+ },
14
+ "scripts": {
15
+ "build": "npx tsc",
16
+ "format": "npx prettier --write ./src/",
17
+ "format:check": "npx prettier --check ./src/",
18
+ "lint": "npx eslint ./src/**/*.ts",
19
+ "version": "npm run build && git add .",
20
+ "ci:version": "changeset version && npm run version",
21
+ "ci:publish": "npm run build && changeset publish"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/Robot-Inventor/astro-link-card.git"
26
+ },
27
+ "keywords": [
28
+ "astro",
29
+ "rehype",
30
+ "rehype-plugin",
31
+ "astro-integration"
32
+ ],
33
+ "author": "Robot-Inventor",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/Robot-Inventor/astro-link-card/issues"
37
+ },
38
+ "homepage": "https://github.com/Robot-Inventor/astro-link-card#readme",
39
+ "devDependencies": {
40
+ "@changesets/changelog-github": "^0.5.0",
41
+ "@changesets/cli": "^2.27.7",
42
+ "@robot-inventor/eslint-config": "^0.2.26",
43
+ "eslint": "^9.8.0",
44
+ "prettier": "^3.3.3",
45
+ "typescript": "^5.5.4"
46
+ },
47
+ "dependencies": {
48
+ "astro": "^4.12.3",
49
+ "rehype-og-card": "^0.4.3"
50
+ }
51
+ }