Fine tune image rendering

This commit is contained in:
Michal Vanko 2021-04-21 15:19:50 +02:00
parent c0aaa3047c
commit 8eba47c5ea
4 changed files with 42 additions and 34 deletions

View File

@ -1,5 +1,3 @@
import path from 'path'
export const renderer = { export const renderer = {
heading(text: string, level: string) { heading(text: string, level: string) {
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-') const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-')
@ -14,15 +12,16 @@ export const renderer = {
` `
}, },
image(href: string, title: string, text: string) { image(href: string, title: string, text: string) {
const file = path.parse(href)
const figcaption = title ? `<figcaption>${title}</figcaption>` : '' const figcaption = title ? `<figcaption>${title}</figcaption>` : ''
const isLocal = !href.startsWith('http')
const src = isLocal ? `${href}?nf_resize=fit&h=640&w=640` : href
return ` return `
<figure> <figure>
<picture> <img
<source srcset="${file.dir}/optimized/${file.name}.webp" type="image/webp" /> alt="${text}"
<img alt="${text}" src="${href}" /> src="${src}"
</picture> />
${figcaption} ${figcaption}
</figure> </figure>
` `

View File

@ -4,6 +4,36 @@
// } // }
</script> </script>
<svelte:head>
<title>Introduction @michalvankodev</title>
</svelte:head>
<header class="index-header">
<figure class="profile-pic">
<picture>
<source
media="(max-width: 550px)"
srcset="images/profile-picture-portrait.jpg"
/>
<img alt="My profile" src="images/profile-picture2.jpg" />
</picture>
</figure>
<p class="motto">
<cite>“Let your ambition carry you.”</cite>
<span>- La Flame</span>
</p>
</header>
<p>
Hey, welcome to my personal website. My name is
<strong>Michal&nbsp;Vanko</strong>
and I'm a
<em> <a href="https://en.wikipedia.org/wiki/Programmer">programmer</a> </em>
. I'll try to share some stories and opinions about things that I'm interested
in.
</p>
<style> <style>
figure, figure,
p { p {
@ -30,30 +60,3 @@
font-size: 1.4em; font-size: 1.4em;
} }
</style> </style>
<svelte:head>
<title>Introduction @michalvankodev</title>
</svelte:head>
<header class="index-header">
<figure class="profile-pic">
<picture>
<source srcset="images/profile-picture.webp" type="image/webp" />
<img alt="My profile picture" src="images/profile-picture.jpg" />
</picture>
</figure>
<p class="motto">
<cite>“Let your ambition carry you.”</cite>
<span>- La Flame</span>
</p>
</header>
<p>
Hey, welcome to my personal website. My name is
<strong>Michal&nbsp;Vanko</strong>
and I'm a
<em> <a href="https://en.wikipedia.org/wiki/Programmer">programmer</a> </em>
. I'll try to share some stories and opinions about things that I'm interested
in.
</p>

BIN
static/images/profile-picture-portrait.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/images/profile-picture2.jpg (Stored with Git LFS) Normal file

Binary file not shown.