762 文字
4 分
[Astro] remark-link-card-plus が神

このブログにリンクカードを実装するため、remark-link-card
を使わせてもらっていた。
しかし、このプラグインにはいくつか問題があった。
箇条書き内のリンクもリンクカードに変換され、ページ上部に飛んでってしまう
これを回避するには、箇条書き内でURLを書くのを諦めるしか無かった
- この問題を指摘するIssueも出ているが、特に応答がなさそう
- https://github.com/gladevise/remark-link-card/issues/18
- ↑このような書き方ができないということ
画像サイズが大きすぎると取得できない
以下のようなエラーが出る。特にYoutubeの動画をリンクカードにするときにしばしば発生。
[remark-link-card] Error: Failed to get the Open Graph data of https://www.youtube.com/watch?v=PAe7tPJqXnQ due to Exceeded the download limit of 1000000 bytes.
エラー文で調べても、他に類似の報告は無かった。
解決
自力で解決しようとしていたら、以下の記事を見つけた。
入れてみたら、なんとこれらの問題が両方とも解決した!!!
CSSについては、以下の記事を参考にそのままremark-link-card-plus
用に修正しました。
/* ブレークポイント: 60ch(Tailwindcss/Typographyのproseのmax-widthを参考に) */.remark-link-card-plus__container { width: 100%; margin-bottom: 1.25em;}
.remark-link-card-plus__card { --padding-x: 1rem; --padding-y: 0.7rem; --border-radius: calc(0.5rem - 1px); border: 1px solid var(--tw-prose-hr); border-radius: calc(var(--border-radius) + 1px); text-decoration: none; display: grid; grid-template-columns: 1fr 116px; gap: 1rem; @media (min-width: 60ch) { grid-template-columns: 1fr 220px; } transition: background-color 150ms;
&:hover { background-color: var(--primary-color); @media (prefers-color-scheme: dark) { background-color: var(--primary-color-lighten); } }}
.remark-link-card-plus__main { display: flex; flex-direction: column; justify-content: center; font-weight: normal;
grid-column: 1; padding: var(--padding-y) 0 var(--padding-y) var(--padding-x); max-width: 100%; min-width: 100%; border-radius: var(--border-radius) 0 0 var(--border-radius);}
/*.remark-link-card-plus__content {}*/
.remark-link-card-plus__title { font-size: 1rem; font-weight: bold; line-height: 1.3; color: var(--tw-prose-headings);
overflow: hidden; display: -webkit-box; text-overflow: ellipsis; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;}
.remark-link-card-plus__description { font-size: 0.8rem; color: #737373; @media (prefers-color-scheme: dark) { color: #a3a3a3; }
margin-bottom: 0.5em;
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; -webkit-line-clamp: 1; line-clamp: 1;}
.remark-link-card-plus__meta { display: flex; align-items: center; gap: 0.5rem;}
.remark-link-card-plus__favicon { margin-top: 0.15rem; margin-bottom: 0;}
.remark-link-card-plus__url { font-size: 0.8rem; color: #525252; @media (prefers-color-scheme: dark) { color: #d4d4d4; }
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; -webkit-line-clamp: 1; line-clamp: 1;}
.remark-link-card-plus__thumbnail { grid-column: 2; aspect-ratio: 1 / 1; @media (min-width: 60ch) { aspect-ratio: 1.91 / 1; }}
.remark-link-card-plus__image { object-fit: cover; height: 100%; width: 100%; margin: 0; border-radius: 0 var(--border-radius) var(--border-radius) 0;}