Skip to content
Snippets Groups Projects
Commit e7a5234c authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Improve ghost html snippet for media

parent 0758b7fa
Branches
Tags
1 merge request!14Version 1.3.0
Pipeline #2858 passed
...@@ -40,8 +40,11 @@ ...@@ -40,8 +40,11 @@
<br> <br>
<div *ngIf="isImage"> <div *ngIf="isImage">
<span class="has-text-weight-bold">Ghost snippet: </span> <span class="has-text-weight-bold">Ghost snippet: </span>
<pre class="hljs code-preview"> <span class="comment">(Ce code html est fait pour intégrer l'image en taille normal. Pour une taille
<code [innerHTML]="ghostSnippet"></code> 'wide' ajoutez la classe 'kg-width-wide' à la balise figure. Pour une taille 'full' ajoutez la classe
'kg-width-full' à la balise figure)</span>
<pre class="hljs code-preview" [innerHTML]="ghostSnippet">
<!-- <code ></code> -->
</pre> </pre>
</div> </div>
</div> </div>
......
...@@ -29,3 +29,9 @@ figure img { ...@@ -29,3 +29,9 @@ figure img {
padding: 0.5rem; padding: 0.5rem;
margin-top: 0.5rem; margin-top: 0.5rem;
} }
.comment {
font-size: 12px;
font-style: italic;
color: $grey-super-light-color;
}
...@@ -35,13 +35,21 @@ export class MediaDetailComponent implements OnInit { ...@@ -35,13 +35,21 @@ export class MediaDetailComponent implements OnInit {
return isImageUrl(this.media.url); return isImageUrl(this.media.url);
} }
// [WARNING] Keep that weird indentation for correct display on the web page
get ghostSnippet() { get ghostSnippet() {
return highlight('html', ` let html;
<figure class="kg-card kg-image-card kg-card-hascaption"> if (this.media.caption) {
<img src="${this.media.url}" alt="${this.media.alt}" class="kg-image"> html = `<figure class="kg-card kg-image-card kg-card-hascaption">
<figcaption> <img src="${this.media.url}" alt="${this.media.alt}" class="kg-image">
${this.media.caption} <figcaption>
</figcaption> ${this.media.caption}
</figure>`).value; </figcaption>
</figure>`;
} else {
html = `<figure class="kg-card kg-image-card">
<img src="${this.media.url}" alt="${this.media.alt}" class="kg-image">
</figure>`;
}
return highlight('html', html).value;
} }
} }
...@@ -95,10 +95,51 @@ ...@@ -95,10 +95,51 @@
</div> </div>
<div class="column is-3 has-text-centered actions"> <div class="column is-3 has-text-centered actions">
<button <button
title="Copier dans le presse-papier le snippet html à copier dans un article ghost pour embarquer l'image" title="Copier dans le presse-papier le snippet html à copier dans un article/page ghost pour embarquer l'image en mode normal"
class="button copy-button" *ngIf="isImage(item.url)" [ngClass]="{'copied': copiedIndex === i}" class="button copy-button" *ngIf="isImage(item.url)" [ngClass]="{'copied': copiedIndex === i}"
(click)="copyGhostHTMLSnippet(item, i)"> (click)="copyGhostHTMLSnippet(item, '', i)">
{{ copiedIndex === i ? 'Copié !' : null }} <span *ngIf="copiedIndex === i && copiedSize === ''; else imageNormal">Copié !</span>
<ng-template #imageNormal>
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<g fill="#242b3f" fill-rule="nonzero">
<path d="M2 3a1 1 0 0 1 0-2h12a1 1 0 0 1 0 2H2zm0 12a1 1 0 0 1 0-2h12a1 1 0 0 1 0 2H2z" opacity=".6">
</path>
<path d="M2 5h12a1 1 0 0 1 1 1v4.001a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z"></path>
</g>
</svg>
</ng-template>
</button>
<button
title="Copier dans le presse-papier le snippet html à copier dans un article/page ghost pour embarquer l'image en mode wide"
class="button copy-button" *ngIf="isImage(item.url)" [ngClass]="{'copied': copiedIndex === i}"
(click)="copyGhostHTMLSnippet(item, 'kg-width-wide', i)">
<span *ngIf="copiedIndex === i && copiedSize === 'kg-width-wide'; else imageWide">Copié !</span>
<ng-template #imageWide>
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<g fill="#242b3f" fill-rule="nonzero">
<path d="M6 3a1 1 0 0 1 0-2h4a1 1 0 0 1 0 2H6zm0 12a1 1 0 0 1 0-2h4a1 1 0 0 1 0 2H6z" opacity=".6">
</path>
<path d="M2 5h12a1 1 0 0 1 1 1v4.001a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z"></path>
</g>
</svg>
</ng-template>
</button>
<button
title="Copier dans le presse-papier le snippet html à copier dans un article/page ghost pour embarquer l'image en mode full"
class="button copy-button" *ngIf="isImage(item.url)" [ngClass]="{'copied': copiedIndex === i}"
(click)="copyGhostHTMLSnippet(item, 'kg-width-full', i)">
<span *ngIf="copiedIndex === i && copiedSize === 'kg-width-full'; else imageFull">Copié !</span>
<ng-template #imageFull>
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<g fill="#242b3f" fill-rule="nonzero">
<path d="M0 2a1 1 0 0 1 2 0v12a1 1 0 0 1-2 0V2zm14 0a1 1 0 0 1 2 0v12a1 1 0 0 1-2 0V2z" opacity=".6">
</path>
<path
d="M10.626 7L9.312 5.691a1 1 0 1 1 1.411-1.417l3.029 3.017c.39.389.392 1.02.005 1.412l-3.029 3.059a1 1 0 0 1-1.421-1.407L10.648 9H5.415l1.342 1.355a1 1 0 0 1-1.422 1.407L2.307 8.703a1 1 0 0 1 .005-1.412L5.34 4.274a1 1 0 0 1 1.412 1.417L5.438 7h5.188z">
</path>
</g>
</svg>
</ng-template>
</button> </button>
<app-crud-buttons [id]="item._id" (delete)="displayDeletePopup($event)"></app-crud-buttons> <app-crud-buttons [id]="item._id" (delete)="displayDeletePopup($event)"></app-crud-buttons>
</div> </div>
......
...@@ -7,13 +7,19 @@ img { ...@@ -7,13 +7,19 @@ img {
} }
.copy-button { .copy-button {
width: 50px; background-color: transparent;
background-position: center; border: none;
background-size: contain; padding-left: 0.25rem;
background-image: url('/assets/img/ghost-logo.png'); padding-right: 0.25rem;
&.copied { svg {
background-image: unset; height: 15px;
}
svg:hover {
g {
fill: #3273dc;
}
} }
} }
......
...@@ -23,6 +23,7 @@ export class MediaComponent implements OnInit, OnDestroy { ...@@ -23,6 +23,7 @@ export class MediaComponent implements OnInit, OnDestroy {
continue: 'Supprimer', continue: 'Supprimer',
}; };
copiedIndex = null; copiedIndex = null;
copiedSize = null;
media: Media[] = []; media: Media[] = [];
searchChangeSub: Subscription; searchChangeSub: Subscription;
...@@ -93,18 +94,25 @@ export class MediaComponent implements OnInit, OnDestroy { ...@@ -93,18 +94,25 @@ export class MediaComponent implements OnInit, OnDestroy {
return isImageUrl(url); return isImageUrl(url);
} }
copyGhostHTMLSnippet(media: Media, id) { copyGhostHTMLSnippet(media: Media, size: string, id) {
navigator['clipboard'].writeText(` if (media.caption) {
<figure class="kg-card kg-image-card kg-card-hascaption"> navigator['clipboard'].writeText(`<figure class="kg-card kg-image-card kg-card-hascaption ${size}">
<img src="${media.url}" alt="${media.alt}" class="kg-image"> <img src="${media.url}" alt="${media.alt}" class="kg-image">
<figcaption> <figcaption>
${media.caption} ${media.caption}
</figcaption> </figcaption>
</figure>`); </figure>`);
} else {
navigator['clipboard'].writeText(`<figure class="kg-card kg-image-card ${size}">
<img src="${media.url}" alt="${media.alt}" class="kg-image">
</figure>`);
}
this.copiedIndex = id; this.copiedIndex = id;
this.copiedSize = size;
setTimeout( setTimeout(
() => { () => {
this.copiedIndex = null; this.copiedIndex = null;
this.copiedSize = null;
}, },
3000, 3000,
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment