Skip to content

Commit

Permalink
Image thumbnails in archive page
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Aug 8, 2020
1 parent 219adff commit 7b91f8e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 48 deletions.
2 changes: 1 addition & 1 deletion layout/_macro/post-collapse.njk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<article itemscope itemtype="http://schema.org/Article">
<header class="post-header">

<div class="post-meta">
<time itemprop="dateCreated"
datetime="{{ moment(post.date).format() }}"
Expand All @@ -34,6 +33,7 @@
{%- endif %}
</div>

{{ post_gallery(post.photos) }}
</header>
</article>

Expand Down
31 changes: 21 additions & 10 deletions layout/_macro/post.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
</span>

{# Gallery support #}
{%- if post.photos and post.photos.length %}
<div class="post-gallery" itemscope itemtype="http://schema.org/ImageGallery">
{%- for photo in post.photos %}
<div class="post-gallery-image">
<img src="{{ url_for(photo) }}" itemprop="contentUrl">
</div>
{%- endfor %}
</div>
{%- endif %}
{{ post_gallery(post.photos) }}

{%- if post.header !== false %}
<header class="post-header">
Expand Down Expand Up @@ -240,7 +232,26 @@

{{ partial('_partials/post/post-footer.njk', {}, {cache: theme.cache.enable}) }}

{{ post_nav(post) }}
{%- if theme.post_navigation and (post.prev or post.next) %}
{%- set prev = post.prev if theme.post_navigation === 'right' else post.next %}
{%- set next = post.next if theme.post_navigation === 'right' else post.prev %}
<div class="post-nav">
<div class="post-nav-item">
{%- if prev %}
<a href="{{ url_for(prev.path) }}" rel="prev" title="{{ prev.title }}">
<i class="fa fa-chevron-left"></i> {{ prev.title }}
</a>
{%- endif %}
</div>
<div class="post-nav-item">
{%- if next %}
<a href="{{ url_for(next.path) }}" rel="next" title="{{ next.title }}">
{{ next.title }} <i class="fa fa-chevron-right"></i>
</a>
{%- endif %}
</div>
</div>
{%- endif %}
</footer>
{% else %}
<footer class="post-footer">
Expand Down
6 changes: 1 addition & 5 deletions layout/_partials/post/post-reward.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

{%- for name, image in theme.reward %}
{%- set builtin = ['wechatpay', 'alipay', 'paypal', 'bitcoin'] %}
{%- if builtin.includes(name) %}
{%- set translation = __('reward.' + name) %}
{% else %}
{%- set translation = name %}
{%- endif %}
{%- set translation = __('reward.' + name) if builtin.includes(name) else name %}
<div>
<img src="{{ url_for(image) }}" alt="{{ author }} {{ translation }}">
<p>{{ translation }}</p>
Expand Down
14 changes: 3 additions & 11 deletions layout/_partials/sidebar/site-overview.njk
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,9 @@
<div class="links-of-author animated">
{%- for name, link in theme.social %}
<span class="links-of-author-item">
{%- set sidebarURL = link.split('||')[0] | trim %}
{%- if theme.social_icons.enable %}
{%- set sidebarIcon = '<i class="' + link.split('||')[1] | trim + ' fa-fw"></i>' %}
{%- else %}
{%- set sidebarIcon = '' %}
{%- endif %}
{%- if theme.social_icons.enable and theme.social_icons.icons_only %}
{%- set sidebarText = '' %}
{%- else %}
{%- set sidebarText = name %}
{%- endif %}
{%- set sidebarURL = link.split('||')[0] | trim %}
{%- set sidebarIcon = '<i class="' + link.split('||')[1] | trim + ' fa-fw"></i>' if theme.social_icons.enable else '' %}
{%- set sidebarText = '' if (theme.social_icons.enable and theme.social_icons.icons_only) else name %}
{{ next_url(sidebarURL, sidebarIcon + sidebarText, {title: name + '' + sidebarURL}) }}
</span>
{%- endfor %}
Expand Down
31 changes: 11 additions & 20 deletions scripts/helpers/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ hexo.extend.helper.register('next_js', function(file, pjax = false) {
return `<script ${pjax ? 'data-pjax ' : ''}src="${src}"></script>`;
});

hexo.extend.helper.register('post_gallery', function(photos) {
if (!photos || !photos.length) return '';
const content = photos.map(photo => `
<div class="post-gallery-image">
<img src="${this.url_for(photo)}" itemprop="contentUrl">
</div>`).join('');
return `<div class="post-gallery" itemscope itemtype="http://schema.org/ImageGallery">
${content}
</div>`;
});

hexo.extend.helper.register('post_edit', function(src) {
const { theme } = this;
if (!theme.post_edit.enable) return '';
Expand All @@ -36,26 +47,6 @@ hexo.extend.helper.register('post_edit', function(src) {
});
});

hexo.extend.helper.register('post_nav', function(post) {
const { theme } = this;
if (theme.post_navigation === false || (!post.prev && !post.next)) return '';
const prev = theme.post_navigation === 'right' ? post.prev : post.next;
const next = theme.post_navigation === 'right' ? post.next : post.prev;
const left = prev ? `
<a href="${this.url_for(prev.path)}" rel="prev" title="${prev.title}">
<i class="fa fa-chevron-left"></i> ${prev.title}
</a>` : '';
const right = next ? `
<a href="${this.url_for(next.path)}" rel="next" title="${next.title}">
${next.title} <i class="fa fa-chevron-right"></i>
</a>` : '';
return `
<div class="post-nav">
<div class="post-nav-item">${left}</div>
<div class="post-nav-item">${right}</div>
</div>`;
});

hexo.extend.helper.register('gitalk_md5', function(path) {
const str = this.url_for(path);
return crypto.createHash('md5').update(str).digest('hex');
Expand Down
9 changes: 8 additions & 1 deletion source/css/_common/components/post/post-gallery.styl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.post-gallery {
display: flex;
margin-bottom: 60px;
min-height: 200px;

.post-gallery-image {
Expand All @@ -22,3 +21,11 @@
}
}
}

.posts-expand .post-gallery {
margin-bottom: 60px;
}

.posts-collapse .post-gallery {
margin: 15px 0;
}

12 comments on commit 7b91f8e

@stevenjoezhang
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enkr1
Copy link

@enkr1 enkr1 commented on 7b91f8e May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but... how to use? 🥺

@enkr1
Copy link

@enkr1 enkr1 commented on 7b91f8e May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried with putting:

photos:
- my_image.png

it does not seem to be able to find my_image.png under the blog page folder

@stevenjoezhang
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enkr1 Use absolute paths e.g. /images/my_image.png

@enkr1
Copy link

@enkr1 enkr1 commented on 7b91f8e May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enkr1 Use absolute paths e.g. /images/my_image.png

it shows as
image

Here is how i declared:

photos:
- /images/terminal.png

@enkr1
Copy link

@enkr1 enkr1 commented on 7b91f8e May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot in advance for any guidance! <3

@stevenjoezhang
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enkr1 Is your blog located in the /blog/ subdirectory? Are the other images in your blog displaying correctly?

@enkr1
Copy link

@enkr1 enkr1 commented on 7b91f8e May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enkr1 Is your blog located in the /blog/ subdirectory? Are the other images in your blog displaying correctly?

yes i could use:

{% asset_img "image.png" "" %}

to show my image

@enkr1
Copy link

@enkr1 enkr1 commented on 7b91f8e May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have my md located in source/_posts/my-blog-page.md and will have a folder created source/_posts/my-blog-page as well

@stevenjoezhang
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enkr1 Currently, image links under the photos section do not support shorthand URLs like asset_img. You need to use the full URL of image.png on the internet (a complete link starting with https), and then insert it into the photos section.

@enkr1
Copy link

@enkr1 enkr1 commented on 7b91f8e May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enkr1 Currently, image links under the photos section do not support shorthand URLs like asset_img. You need to use the full URL of image.png on the internet (a complete link starting with https), and then insert it into the photos section.

wow... i got it. you gotta put the folder name too:

photos:
- "my-blog-page/my-picture.png"

@enkr1
Copy link

@enkr1 enkr1 commented on 7b91f8e May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you so much @stevenjoezhang <3

Please sign in to comment.