|
160 | 160 | </h2>
|
161 | 161 | <div>{{ packageInvalidTagsString }}</div>
|
162 | 162 | </section>
|
| 163 | + <section class="col-12"> |
| 164 | + <h2>Badge <small>(click to copy)</small></h2> |
| 165 | + <div> |
| 166 | + <a |
| 167 | + :href="badgeUrl" |
| 168 | + data-tooltip="Copied" |
| 169 | + class="tooltip tooltip-click" |
| 170 | + @click.prevent="onCopyBadgeVersion" |
| 171 | + > |
| 172 | + <img :src="badgeVersionImageUrl" /> |
| 173 | + </a> |
| 174 | + </div> |
| 175 | + </section> |
163 | 176 | </div>
|
164 | 177 | </div>
|
165 | 178 | </div>
|
|
172 | 185 |
|
173 | 186 | <script>
|
174 | 187 | import axios from "axios";
|
| 188 | +import escape from "escape-html"; |
175 | 189 | import copy from "copy-to-clipboard";
|
176 | 190 | import marked from "marked";
|
177 | 191 | import { noCase } from "change-case";
|
@@ -306,6 +320,11 @@ export default {
|
306 | 320 | return cli;
|
307 | 321 | } else return "not available";
|
308 | 322 | },
|
| 323 | + badgeVersionHtml() { |
| 324 | + return `<a href="${escape(this.badgeUrl)}"><img src="${escape( |
| 325 | + this.badgeVersionImageUrl |
| 326 | + )}" /></a>`; |
| 327 | + }, |
309 | 328 | readmeHtml() {
|
310 | 329 | if (!this.$data.readmeRaw) return "";
|
311 | 330 | else {
|
@@ -368,6 +387,11 @@ export default {
|
368 | 387 | text: "Edit this package"
|
369 | 388 | };
|
370 | 389 | },
|
| 390 | + badgeUrl() { |
| 391 | + return urljoin(this.$site.themeConfig.domain, this.$page.path); |
| 392 | + }, |
| 393 | + badgeVersionImageUrl() { |
| 394 | + return `https://img.shields.io/npm/v/${this.$package.name}?label=openupm®istry_uri=https://package.openupm.com`; |
371 | 395 | }
|
372 | 396 | },
|
373 | 397 | watch: {
|
@@ -448,8 +472,11 @@ See more in the [${this.$package.repo}](${this.$package.repoUrl}) repository.
|
448 | 472 | console.error(error);
|
449 | 473 | }
|
450 | 474 | },
|
451 |
| - onCopyClick() { |
| 475 | + onCopyCli() { |
452 | 476 | copy(this.packageInstallCli, { format: "text/plain" });
|
| 477 | + }, |
| 478 | + onCopyBadgeVersion() { |
| 479 | + copy(this.badgeVersionHtml, { format: "text/plain" }); |
453 | 480 | }
|
454 | 481 | }
|
455 | 482 | };
|
|
0 commit comments