Skip to content

Commit 819a0e4

Browse files
authored
Merge pull request #17 from patrick91/feature/fixes-and-improvements
Fix bugs and add new small features
2 parents dcd2d32 + 153fa00 commit 819a0e4

31 files changed

+5871
-2740
lines changed

.github/workflows/format-check.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Format Check
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
format-check:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: "18"
20+
21+
- name: Install pnpm
22+
uses: pnpm/action-setup@v4
23+
with:
24+
version: 8
25+
26+
- name: Install dependencies
27+
run: pnpm install
28+
29+
- name: Check formatting
30+
run: npx prettier . --check

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

.prettierignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules/
2+
dist/
3+
build/
4+
.next/
5+
.cache/
6+
.parcel-cache/
7+
.DS_Store
8+
*.log
9+
pnpm-lock.yaml
10+
package-lock.json

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"plugins": ["prettier-plugin-astro"],
3+
"overrides": [
4+
{
5+
"files": "*.astro",
6+
"options": {
7+
"parser": "astro"
8+
}
9+
}
10+
]
11+
}

package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
{
2-
"name": "astro-meta-tags-workspace"
3-
}
2+
"name": "astro-meta-tags-workspace",
3+
"private": true,
4+
"scripts": {
5+
"format": "prettier . --write",
6+
"format:check": "prettier . --check",
7+
"prepare": "husky install"
8+
},
9+
"devDependencies": {
10+
"prettier": "^3.3.3",
11+
"prettier-plugin-astro": "^0.14.1",
12+
"husky": "^9.0.11",
13+
"lint-staged": "^15.2.9"
14+
},
15+
"lint-staged": {
16+
"*.{js,jsx,ts,tsx,astro,json,md}": [
17+
"prettier --write"
18+
]
19+
}
20+
}

packages/astro-meta-tags/package.json

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
{
2-
"name": "astro-meta-tags",
3-
"version": "0.3.2",
4-
"author": "Patrick Arminio",
5-
"repository": "github:patrick91/astro-meta-tags",
6-
"license": "MIT",
7-
"description": "A Dev Toolbar extension to debug meta tags in your Astro website",
8-
"keywords": [
9-
"astro",
10-
"withastro",
11-
"astro-component",
12-
"astro-integration",
13-
"devtools"
14-
],
15-
"main": "./src/index.ts",
16-
"exports": {
17-
".": "./src/index.ts"
18-
},
19-
"files": [
20-
"src",
21-
"README.md"
22-
],
23-
"scripts": {
24-
"dev": "astro dev",
25-
"start": "astro dev",
26-
"preview": "astro preview",
27-
"astro": "astro"
28-
},
29-
"devDependencies": {
30-
"@astrojs/check": "^0.3.4",
31-
"@astrojs/mdx": "^2.0.3",
32-
"@astrojs/rss": "^4.0.1",
33-
"@astrojs/sitemap": "^3.0.4",
34-
"astro": "^4.1.0",
35-
"rimraf": "^5.0.5",
36-
"typescript": "^5.3.3"
37-
},
38-
"peerDependencies": {
39-
"astro": "^4.0.0 || ^5.0.0-beta.0"
40-
}
2+
"name": "astro-meta-tags",
3+
"version": "0.4.0",
4+
"author": "Patrick Arminio",
5+
"repository": "github:patrick91/astro-meta-tags",
6+
"license": "MIT",
7+
"description": "A Dev Toolbar extension to debug meta tags in your Astro website",
8+
"keywords": [
9+
"astro",
10+
"withastro",
11+
"astro-component",
12+
"astro-integration",
13+
"devtools"
14+
],
15+
"main": "./src/index.ts",
16+
"exports": {
17+
".": "./src/index.ts"
18+
},
19+
"files": [
20+
"src",
21+
"README.md"
22+
],
23+
"scripts": {
24+
"dev": "astro dev",
25+
"start": "astro dev",
26+
"preview": "astro preview",
27+
"astro": "astro"
28+
},
29+
"devDependencies": {
30+
"@astrojs/check": "^0.3.4",
31+
"@astrojs/mdx": "^2.0.3",
32+
"@astrojs/rss": "^4.0.1",
33+
"@astrojs/sitemap": "^3.0.4",
34+
"astro": "^4.1.0",
35+
"rimraf": "^5.0.5",
36+
"typescript": "^5.3.3"
37+
},
38+
"peerDependencies": {
39+
"astro": "^4.0.0 || ^5.0.0-beta.0"
40+
}
4141
}

packages/astro-meta-tags/src/toolbar.ts

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,73 @@ const getWindowContent = () => {
1313
const themeColorMeta = document.querySelector("meta[name='theme-color']");
1414
const themeColor = themeColorMeta?.getAttribute("content");
1515

16-
const getTagTuple = (tag: Element, attributeName: string = "property") =>
17-
[tag.getAttribute(attributeName), tag.getAttribute("content")] as [
18-
string,
19-
string,
20-
];
16+
const getTagTuple = (tag, attributeName = "property") => [
17+
tag.getAttribute(attributeName) ?? "",
18+
tag.getAttribute("content") ?? "",
19+
];
2120

22-
const ogMetaTags = Array.from(
21+
const ogMetaTags: string[][] = Array.from(
2322
document.querySelectorAll("meta[property^='og:']"),
24-
).map((tag) => getTagTuple(tag, "property"));
23+
)
24+
.map((tag) => getTagTuple(tag, "property"))
25+
.map(([a, b]) => [a ?? "", b ?? ""]);
2526

26-
const twitterMetaTags = Array.from(
27+
const twitterMetaTags: string[][] = Array.from(
2728
document.querySelectorAll("meta[name^='twitter:']"),
28-
).map((tag) => getTagTuple(tag, "name"));
29-
30-
const getSingleTagHtml = ([property, content]: [
31-
string,
32-
string | undefined | null,
33-
]) => {
29+
)
30+
.map((tag) => getTagTuple(tag, "name"))
31+
.map(([a, b]) => [a ?? "", b ?? ""]);
32+
33+
const alternateLinks: string[][] = Array.from(
34+
document.querySelectorAll("link[rel='alternate'][hreflang]"),
35+
)
36+
.map((tag) => [
37+
tag.getAttribute("hreflang") ?? "",
38+
tag.getAttribute("href") ?? "",
39+
])
40+
.map(([a, b]) => [a ?? "", b ?? ""]);
41+
42+
const iconLinks: string[][] = Array.from(
43+
document.querySelectorAll("link[rel='icon'], link[rel='apple-touch-icon']"),
44+
)
45+
.map((tag) => [
46+
tag.getAttribute("rel") ?? "",
47+
tag.getAttribute("href") ?? "",
48+
tag.getAttribute("sizes") ?? "",
49+
tag.getAttribute("type") ?? "",
50+
])
51+
.map(([rel, href, sizes, type]) => [
52+
rel === "apple-touch-icon" ? "Apple Touch Icon" : "Favicon",
53+
href ?? "",
54+
sizes ? `${sizes}` : "",
55+
type ?? "",
56+
])
57+
.map(([label, href, sizes, type]) => [
58+
sizes ? `${label} (${sizes})` : label,
59+
href,
60+
]);
61+
62+
const getSingleTagHtml = ([property, content]: [string, string]) => {
3463
let contentTag: HTMLElement | Text;
3564

3665
if (!content) {
3766
content = "N/A";
3867
}
3968

40-
if (["og:image", "twitter:image"].includes(property)) {
69+
if (
70+
["og:image", "twitter:image"].includes(property) ||
71+
property.includes("Favicon") ||
72+
property.includes("Apple Touch Icon")
73+
) {
4174
contentTag = document.createElement("img");
4275
contentTag.setAttribute("src", content);
76+
if (
77+
property.includes("Favicon") ||
78+
property.includes("Apple Touch Icon")
79+
) {
80+
contentTag.style.maxWidth = "32px";
81+
contentTag.style.height = "auto";
82+
}
4383
} else if (property === "Theme color" && content !== "N/A") {
4484
contentTag = document.createElement("div");
4585
contentTag.style.width = "100px";
@@ -64,13 +104,13 @@ const getWindowContent = () => {
64104

65105
const getTagsHtml = (
66106
title: string,
67-
tags: [string, string | undefined | null][],
107+
tags: string[][],
68108
wrapWithDetails = true,
69109
) => {
70110
const dl = document.createElement("dl");
71111

72-
for (const tag of tags) {
73-
dl.append(getSingleTagHtml(tag));
112+
for (const [property, content] of tags) {
113+
dl.append(getSingleTagHtml([property, content]));
74114
}
75115

76116
if (!wrapWithDetails) {
@@ -90,17 +130,22 @@ const getWindowContent = () => {
90130
const standardTags = [
91131
["Page title", pageTitle],
92132
["Canonical URL", canonicalUrl],
93-
["Meta title", metaTitle],
94133
["Meta description", metaDescription],
95134
["Theme color", themeColor],
96-
] as [string, string | undefined | null][];
135+
].map(([k, v]) => [k ?? "", v ?? ""]);
97136

98-
let standardTagsHtml = getTagsHtml("Standard", standardTags, false);
137+
const standardTagsHtml = getTagsHtml("Standard", standardTags, false);
99138

100-
let ogTagsHtml =
139+
const ogTagsHtml =
101140
ogMetaTags.length > 0 ? getTagsHtml("Open Graph", ogMetaTags) : "";
102-
let twitterTagsHtml =
141+
const twitterTagsHtml =
103142
twitterMetaTags.length > 0 ? getTagsHtml("Twitter", twitterMetaTags) : "";
143+
const alternateTagsHtml =
144+
alternateLinks.length > 0
145+
? getTagsHtml("Alternate Languages", alternateLinks)
146+
: "";
147+
const iconTagsHtml =
148+
iconLinks.length > 0 ? getTagsHtml("Icons", iconLinks) : "";
104149

105150
return /* html */ `
106151
<style>
@@ -160,8 +205,10 @@ const getWindowContent = () => {
160205
</style>
161206
162207
${standardTagsHtml}
208+
${iconTagsHtml}
163209
${ogTagsHtml}
164210
${twitterTagsHtml}
211+
${alternateTagsHtml}
165212
166213
<hr />
167214
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"compilerOptions": {
3-
"strictNullChecks": true
4-
}
5-
}
2+
"compilerOptions": {
3+
"strictNullChecks": true
4+
}
5+
}

packages/demo/astro.config.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { defineConfig } from 'astro/config';
2-
import mdx from '@astrojs/mdx';
1+
import { defineConfig } from "astro/config";
2+
import mdx from "@astrojs/mdx";
33

4-
import sitemap from '@astrojs/sitemap';
4+
import sitemap from "@astrojs/sitemap";
55
import astroMetaTags from "astro-meta-tags";
66

77
// https://astro.build/config
88
export default defineConfig({
9-
site: 'https://example.com',
10-
integrations: [mdx(), sitemap(), astroMetaTags()],
9+
site: "https://example.com",
10+
integrations: [mdx(), sitemap(), astroMetaTags()],
1111
});

packages/demo/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
"astro": "astro"
1111
},
1212
"dependencies": {
13-
"@astrojs/check": "^0.3.4",
14-
"@astrojs/mdx": "^2.0.3",
15-
"@astrojs/rss": "^4.0.1",
16-
"@astrojs/sitemap": "^3.0.4",
17-
"astro": "^4.1.1",
13+
"@astrojs/check": "^0.9.4",
14+
"@astrojs/mdx": "^4.3.0",
15+
"@astrojs/rss": "^4.0.12",
16+
"@astrojs/sitemap": "^3.4.1",
17+
"astro": "^5.11.0",
1818
"astro-meta-tags": "workspace:*",
19-
"typescript": "^5.3.3"
19+
"typescript": "^5.8.3"
2020
}
21-
}
21+
}

0 commit comments

Comments
 (0)