<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jean-Yves Gastaud</title>
    <description>The latest articles on DEV Community by Jean-Yves Gastaud (@jygastaud).</description>
    <link>https://dev.to/jygastaud</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F151911%2F1bcfa646-9924-4397-8f9c-54f5eb3f7b8e.png</url>
      <title>DEV Community: Jean-Yves Gastaud</title>
      <link>https://dev.to/jygastaud</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jygastaud"/>
    <language>en</language>
    <item>
      <title>Install and configure Renovate Bot on GitLab CE</title>
      <dc:creator>Jean-Yves Gastaud</dc:creator>
      <pubDate>Sat, 27 Nov 2021 15:14:35 +0000</pubDate>
      <link>https://dev.to/jygastaud/install-and-configure-renovate-bot-on-gitlab-ce-lkg</link>
      <guid>https://dev.to/jygastaud/install-and-configure-renovate-bot-on-gitlab-ce-lkg</guid>
      <description>&lt;p&gt;&lt;a href="https://renovatebots.com"&gt;Renovate Bot&lt;/a&gt; is a tool to control the versions of dependencies of your projects.&lt;/p&gt;

&lt;p&gt;It can be compared to the &lt;a href="https://github.com/dependabot"&gt;Dependabot&lt;/a&gt; project which is available on GitHub.&lt;/p&gt;

&lt;p&gt;In this article, we will explore how to install and configure Renovate to run on a Gitlab CE instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;In order to follow the initialization process you must be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create groups and projects&lt;/li&gt;
&lt;li&gt;Have access or install at least 1 GitLab Runner with a docker executor&lt;/li&gt;
&lt;li&gt;Have a GitHub account (even if we are going to use GitLab, it will be used to get the release notes of the projects)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Initialization
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Project structure
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;code&gt;Renovate&lt;/code&gt; project group&lt;/li&gt;
&lt;li&gt;Create 2 projects in the group

&lt;ul&gt;
&lt;li&gt;a &lt;code&gt;renovate-config&lt;/code&gt; project which will contain configuration files that can be shared with all GitLab projects;&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;renovate-runner&lt;/code&gt; project which will contain the configurations to dedicate to the Renovate container.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Gitab user
&lt;/h3&gt;

&lt;p&gt;As the name of the project indicates (Renovate &lt;strong&gt;Bot&lt;/strong&gt; ) we will have to create a user account representing our Bot.&lt;/p&gt;

&lt;p&gt;For our example, we will call it &lt;code&gt;Renovate Bot &amp;lt;renovatebot@example.com&amp;gt;&lt;/code&gt; and the username &lt;code&gt;renovatebot&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This user will be used for 2 things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;merge requests, commits… will be created by the Bot ;&lt;/li&gt;
&lt;li&gt;restrict renovate’s rights to browse only those projects on which it is explicitly invited.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Renovate-runner project configuration
&lt;/h2&gt;

&lt;p&gt;We will start by working on the runner part. Let’s go to the &lt;code&gt;renovate-runner&lt;/code&gt; project we created earlier.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creation of user tokens (PAT : Personal Access Token)
&lt;/h3&gt;

&lt;h4&gt;
  
  
  GitLab
&lt;/h4&gt;

&lt;p&gt;On your GitLab instance, log in with the &lt;code&gt;renovatebot&lt;/code&gt; account created earlier.&lt;/p&gt;

&lt;p&gt;We’ll create an Access Token via your user profile (/-/profile/personal_access_tokens).&lt;/p&gt;

&lt;p&gt;Name the token whatever you like (&lt;code&gt;renovatebot&lt;/code&gt; for example) and choose the following scopes as &lt;a href="https://docs.renovatebot.com/getting-started/running/#gitlab"&gt;indicated in the documentation&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;read_user&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;api&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;write_repository&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Copy the token and go back to the &lt;code&gt;renovate-runner&lt;/code&gt; project, in the CI/CD Settings (menu &lt;code&gt;Settings&lt;/code&gt; &amp;gt; &lt;code&gt;CI/CD&lt;/code&gt; &amp;gt; &lt;code&gt;Variables&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;and create a new variable named &lt;code&gt;RENOVATE_TOKEN&lt;/code&gt; with the retrieved token value.&lt;/p&gt;

&lt;h4&gt;
  
  
  GitHub
&lt;/h4&gt;

&lt;p&gt;In order to be able to retrieve release notes from projects and not be subject to the limitations of the GitHub API, we will need to create a GitHub and create a &lt;a href="https://docs.renovatebot.com/getting-started/running/#githubcom-token-for-release-notes"&gt;Personal Access Token&lt;/a&gt; there.&lt;/p&gt;

&lt;p&gt;Copy the token and go back to the &lt;code&gt;renovate-runner&lt;/code&gt; project, in the CI/CD Settings (menu &lt;code&gt;Settings&lt;/code&gt; &amp;gt; &lt;code&gt;CI/CD&lt;/code&gt; &amp;gt; &lt;code&gt;Variables&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;and create a new variable named &lt;code&gt;GITHUB_COM_TOKEN&lt;/code&gt; with the value of the recovered token.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image: renovate/renovate:29 

variables:
  RENOVATE_BASE_DIR: $CI_PROJECT_DIR/renovate
  RENOVATE_GIT_AUTHOR: Renovate Bot &amp;lt;renovatebot@exemple.com&amp;gt;
  RENOVATE_OPTIMIZE_FOR_DISABLED: 'true'
  RENOVATE_REPOSITORY_CACHE: 'true'
  LOG_LEVEL: debug

cache:
  key: ${CI_COMMIT_REF_SLUG}-renovate
  paths:
    - $CI_PROJECT_DIR/renovate

renovate:
  stage: deploy
  resource_group: production
  only:
    - schedules
  script:
    - renovate $RENOVATE_EXTRA_FLAGS

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Renovate offers most of these configurations as environment variables. However, to be able to use the bot in other contexts than GitLab (a manual launch for example), I only kept the GitLab specific parameters in the &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;The rest of the configurations are in the &lt;code&gt;config.js&lt;/code&gt; file that we’ll look at right now. ⬇️&lt;/p&gt;

&lt;h3&gt;
  
  
  Renovate configuration file
&lt;/h3&gt;

&lt;p&gt;Renovate is based on a configuration file &lt;code&gt;config.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It defines the Git platform to use, the &lt;a href="https://docs.renovatebot.com/self-hosted-configuration/"&gt;configuration options&lt;/a&gt; of the runner and the &lt;a href="https://docs.renovatebot.com/config-presets/"&gt;configuration profiles (Config Presets)&lt;/a&gt; which will be applied for all the projects &lt;code&gt;onboardingConfig&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
        endpoint: 'https://[url of gitlab]/api/v4/',
        platform: 'gitlab',
        persistRepoData: true,
        logLevel: 'debug',
        onboardingConfig: {
                'extends': [
                        "local&amp;gt;groups/subgroups/renovate/renovate-config"
                ],
        },
        autodiscover: true,
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Recurring task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;CI/CD menu &amp;gt; Schedules&lt;/li&gt;
&lt;li&gt;Create a new scheduled task with the frequency you want (I made the choice, totally arbitrary, to run the analysis twice a day) and to trigger.&lt;/li&gt;
&lt;li&gt;Save&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Configuration of default configurations
&lt;/h2&gt;

&lt;p&gt;In the &lt;code&gt;renovate-config&lt;/code&gt; project we will create a simple &lt;code&gt;renovate.json&lt;/code&gt; file which will be the one searched by default by the &lt;code&gt;config.json&lt;/code&gt; file and in particular the line &lt;code&gt;"local&amp;gt;groups/subgroups/renovate/renovate-config"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here are the choices I made:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; {
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "packageRules": [
    {
      "depTypeList": ["devDependencies", "require-dev"],
      "updateTypes": ["patch", "minor", "digest"],
      "groupName": "devDependencies (non-major)"
    }
  ],
  "extends": [
    "config:base",
    ":preserveSemverRanges",
    ":dependencyDashboard",
    ":rebaseStalePrs",
    ":enableVulnerabilityAlertsWithLabel('security')",
    ":group:recommended"
  ]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;packageRules&lt;/code&gt; allows to create new groupings. In our case, this allows us to have a single Merge Request containing all the development dependencies of the project when they are not major.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Extends&lt;/code&gt; allows us to define the rules/configs presets that we want to activate. In particular, we activate the &lt;a href="https://docs.renovatebot.com/key-concepts/dashboard/"&gt;Dependency Dashboard&lt;/a&gt; which allows us to follow in a ticket the status of all available updates and/or current MRs and various &lt;a href="https://docs.renovatebot.com/presets-group/"&gt;Group Presets&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Activate the bot for projects
&lt;/h2&gt;

&lt;p&gt;With these configurations, each project that wants to activate the bot has only 4 steps to follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the user &lt;code&gt;renovatebot&lt;/code&gt; on the project, with at least a &lt;code&gt;contributor&lt;/code&gt; right&lt;/li&gt;
&lt;li&gt;Enable the &lt;code&gt;issues&lt;/code&gt; for the &lt;code&gt;dependency Dashboard&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Enable &lt;code&gt;merge requests&lt;/code&gt; for first with a 1st Merge Request to create the renovate configuration, then the MRs associated with the updates to apply.&lt;/li&gt;
&lt;li&gt;Refine the Renovate configurations according to the specificities of your project&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that’s it 🍾&lt;/p&gt;

&lt;p&gt;We now have a Renovate bot that runs regularly and will update all the repositories it has access to.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Sorting tags from a Git repo using semantic versioning</title>
      <dc:creator>Jean-Yves Gastaud</dc:creator>
      <pubDate>Mon, 20 Sep 2021 21:10:00 +0000</pubDate>
      <link>https://dev.to/jygastaud/sorting-tags-from-a-git-repo-using-semantic-versioning-42nb</link>
      <guid>https://dev.to/jygastaud/sorting-tags-from-a-git-repo-using-semantic-versioning-42nb</guid>
      <description>&lt;p&gt;A quick post today to tell you about a recent discovery in Git's sorting functions and tags based on &lt;a href="https://semver.org/"&gt;semantic versioning&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By default, if you run the &lt;code&gt;git tag -l&lt;/code&gt; command, Git will do an alphabetical sort.&lt;/p&gt;

&lt;p&gt;However, this sorting gives confusing results when the tags use semantic versioning notation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git tag -l
v2.6.1
v2.6.10
v2.6.11
v2.6.12
v2.6.2
v2.6.3
v2.6.4
v2.6.5
v2.6.6
v2.6.7
v2.6.8
v2.6.9
v2.7.0

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice here the sequence &lt;code&gt;v2.6.10&lt;/code&gt;, &lt;code&gt;v2.6.11&lt;/code&gt; and &lt;code&gt;v2.6.12&lt;/code&gt; which is interposed between version &lt;code&gt;v2.6.1&lt;/code&gt; and &lt;code&gt;v2.6.2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To solve this problem, it is possible to use the &lt;code&gt;--sort&lt;/code&gt; function with the &lt;code&gt;version&lt;/code&gt; attribute in Git.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git tag --sort=version:refname

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will display the sorted results consistently:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git tag --sort=version:refname
v2.6.1
v2.6.2
v2.6.3
v2.6.4
v2.6.5
v2.6.6
v2.6.7
v2.6.8
v2.6.9
v2.6.10
v2.6.11
v2.6.12
v2.7.0

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Azure-cli, active autocomplete in Zsh on Ubuntu.</title>
      <dc:creator>Jean-Yves Gastaud</dc:creator>
      <pubDate>Tue, 26 Nov 2019 22:35:18 +0000</pubDate>
      <link>https://dev.to/jygastaud/azure-cli-active-autocomplete-in-zsh-on-ubuntu-2d7i</link>
      <guid>https://dev.to/jygastaud/azure-cli-active-autocomplete-in-zsh-on-ubuntu-2d7i</guid>
      <description>&lt;p&gt;Out of the box, Azure-cli doesn't have autocomplete activated in Zsh and Oh-My-Zsh framework doesn't have plugin available natively.&lt;/p&gt;

&lt;p&gt;However, Azure-cli comes with an autocomplete script that should be located in &lt;code&gt;bash_completion.d&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;In my setup, using Ubuntu 18.04, I found the &lt;code&gt;azure-cli&lt;/code&gt; script in &lt;code&gt;/etc/bash_completion.d/&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;Now we just need to load the autocomplete script inside our &lt;code&gt;~/.zshrc&lt;/code&gt; with the following line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source /etc/bash_completion.d/azure-cli
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Save and reload your terminal. Done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional notes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If you encounter an error when restarting, you may have to add that line before the script loading to ensure cross compatibility between bash and zsh script
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;autoload -U +X bashcompinit &amp;amp;&amp;amp; bashcompinit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Looking at different blog post, you may find that the script is called &lt;code&gt;az&lt;/code&gt;, not &lt;code&gt;azure-cli&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;According to the directory I found it, the script was natively loaded if I use bash shell. If you use bash and doesn't have autocomplete activate, you probably have to search for &lt;code&gt;azure-cli&lt;/code&gt; or &lt;code&gt;az&lt;/code&gt; script and load it to your &lt;code&gt;~/.bashrc&lt;/code&gt; file.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>azure</category>
      <category>zsh</category>
      <category>azurecli</category>
      <category>az</category>
    </item>
    <item>
      <title>Hugo - Generate alternative images that can be used in the homepage</title>
      <dc:creator>Jean-Yves Gastaud</dc:creator>
      <pubDate>Thu, 11 Apr 2019 15:56:26 +0000</pubDate>
      <link>https://dev.to/jygastaud/gohugo-generate-image-declinations-that-can-be-used-as-a-home-page-530j</link>
      <guid>https://dev.to/jygastaud/gohugo-generate-image-declinations-that-can-be-used-as-a-home-page-530j</guid>
      <description>&lt;p&gt;Original article in French on &lt;a href="https://gastaud.io/article/hugo-homepage-images-processing/"&gt;my blog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GoHugo, since version 0.32, is able to manage &lt;a href="https://gohugo.io/about/new-in-032/#page-resources"&gt;dedicated one-page resources&lt;/a&gt;&lt;br&gt;
as well as to generate &lt;a href="https://gohugo.io/about/new-in-032/#image-processing"&gt;image declinations&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This feature is particularly useful for automatically managing responsible declinations of these images and using them in a template or shortcode.&lt;/p&gt;

&lt;p&gt;It works perfectly when you are in a content.&lt;/p&gt;
&lt;h2&gt;
  
  
  So what's the problem?
&lt;/h2&gt;

&lt;p&gt;Let's assume that we want to use responsible images on the homepage of our site.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The home page is not part of a section or bundle and therefore does not have access to resources&lt;/li&gt;
&lt;li&gt;Files placed in the &lt;code&gt;static&lt;/code&gt; directory are not treated as resources by Hugo&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It will therefore be necessary to manage "by hand", the declination of these images and include them manually in our template.&lt;/p&gt;

&lt;p&gt;To simplify, we have the following aborescence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
| content
| | | _index.md
| layouts
| | | index.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What? But I have too many images to decline and the content changes often?!
&lt;/h2&gt;

&lt;p&gt;To automate the generation process, we will use the &lt;a href="https://gohugo.io/news/0.35-relnotes/"&gt;Headless Bundles&lt;/a&gt; introduced in version 0.35.&lt;/p&gt;

&lt;p&gt;This new type of bundle allows you to manage content that will not produce a full page when rendered by Hugo.&lt;/p&gt;

&lt;p&gt;It is therefore convenient to use it to manage blocks, messages... which are then injected into the pages.&lt;/p&gt;

&lt;p&gt;By using this type of bundle and combining it with the image generation functionality, we will be able to automatically obtain our various image declinations.&lt;/p&gt;

&lt;p&gt;We will follow the following steps.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating a new bundle &lt;code&gt;headless-img&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;We will now have the following content tree structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
| content
| | | _index.md
| | | headless-img
| | | | | images
| | | | | | my_image.png
| | | | index.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The file &lt;code&gt;headless-img/index.md&lt;/code&gt; will contain&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+++
headless = true
title = "homepage images"
+++

{{{&amp;lt; imghp src="images/mon_image.png" alt="A nice image for our homepage" &amp;gt;}}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So we have created here a &lt;code&gt;headless&lt;/code&gt; resource that will call a hugo shortcode named &lt;code&gt;imghp&lt;/code&gt; and that takes a path and an alternative text as parameters.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating the shortcode
&lt;/h4&gt;

&lt;p&gt;In the &lt;code&gt;layouts/shortcodes&lt;/code&gt; aborescence we will create a new file named &lt;code&gt;imghp.html&lt;/code&gt; which will contain the logic of generating our images and their rendering.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{ /* The shortcode for HP's responsive images */ }}

{{/* get file that matches the filename as specified as src=""" in shortcode */}}
{{ $src := (.Site.GetPage "/headless-img").Resources.GetMatch (printf "*%s**" (.Get "src") }}}

{{/* set image sizes, these are hardcoded for now, x dictates that images are resized to this width */}}

{{ $tinyw := default "500x" }}}
{{ $smallw := default "800x" }}}
{{ $mediumw := default "1200x" }}}
{{ $largew := default "1500x" }}}

{{/* resize the src image to the given sizes */}}

{{{.Scratch.Set "tiny" ($src.Resize $tinyw) }}
{{{.Scratch.Set "small" ($src.Resize $smallw) }}
{{{.Scratch.Set "medium" ($src.Resize $mediumw) }}
{{{.Scratch.Set "large" ($src.Resize $largew) }}

{{/* add the processed images to the scratch */}}

{{$tiny :=.Scratch.Get "tiny" }}
{{ $small :=.Scratch.Get "small" }}
{{ $medium :=.Scratch.Get "medium" }}
{{$large :=.Scratch.Get "wide" }}

{{/* only use images smaller than or equal to the src (original) image size, as Hugo will upscale small images */}}
{{/* set the sizes attribute to (min-width: 35em) 1200px, 100vw unless overridden in shortcode */}}

&amp;lt;img 
{{{with .Get "sizes" }}sizes='{{.}}'{{ else }}sizes="(min-width: 35em) 1200px, 100vw"{{end }}
srcset=''
{{if ge $src.Width "500" }}}
    {{ with $tiny.RelPermalink }}{{{.}} 500w{{{end }}
{{end }}
{{if ge $src.Width "800" }}}
    {{ with $small.RelPermalink }}, {{.}} 800w{{{{end }}
{{end }}
{{if ge $src.Width "1200" }}}
    {{ with $medium.RelPermalink }}, {{.}} 1200w{{{end }}
{{end }}
{{if ge $src.Width "1500" }}}
    {{with $large.RelPermalink }}, {{.}} 1500w {{{end }}
{{end }}''.
{{if.Get $medium }}}
    src="{{$medium.RelPermalink }}" 
{{ else }}}
    src="{{$src.RelPermalink }}}" 
{{end }}
{{{with.Get "alt" }}alt='{{.}}'{{{end }}&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This template can be found on many sites as an example.&lt;/p&gt;

&lt;p&gt;The main difference with the others is in this line:&lt;br&gt;&lt;br&gt;
&lt;code&gt;{{{$src := (.Site.GetPage "/headless-img").Resources.GetMatch (printf "*%s*") (.Get "src") }}}&lt;/code&gt;&lt;br&gt;&lt;br&gt;
which allows us to retrieve the resources of the &lt;code&gt;headless-img&lt;/code&gt; bundle.&lt;/p&gt;

&lt;p&gt;When this shortcode is executed, it will look for the image defined in the &lt;code&gt;headless-img/index.md&lt;/code&gt; file and automatically generate the declinations.&lt;/p&gt;

&lt;h4&gt;
  
  
  And now, how do I display this on my homepage?
&lt;/h4&gt;

&lt;p&gt;All we have to do now is call our bundle in our template &lt;code&gt;index.html&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  If you have only one single index.md index content
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{define "content" }}
  {{ /* The rendering of the headless section. Assume */ }}
  {{$headless :=.Site.GetPage "/headless-img" }}
  {{{$headless.Content }}
{{end }}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  If you need to render multiple.md files based on a name. &lt;code&gt;img1&lt;/code&gt;, &lt;code&gt;img2&lt;/code&gt;... by example
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{define "content" }}
  {{$headless :=.Site.GetPage "/headless-img" }}
  {{ $reusablePages:= $headless.Resources.Match "img*" }}
  {{range $reusablePages }}
    {{{.Content }}}
  {{end }}
{{end }}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And that's it, now your images are well rendered on your homepage and their responsive versions are also available.&lt;/p&gt;

&lt;p&gt;Translated with &lt;a href="http://www.DeepL.com/Translator"&gt;www.DeepL.com/Translator&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gohugo</category>
      <category>responsive</category>
      <category>image</category>
      <category>hugo</category>
    </item>
    <item>
      <title>Manage distinct profiles in Git</title>
      <dc:creator>Jean-Yves Gastaud</dc:creator>
      <pubDate>Tue, 02 Apr 2019 14:10:47 +0000</pubDate>
      <link>https://dev.to/jygastaud/manage-distinct-profiles-in-git-1b56</link>
      <guid>https://dev.to/jygastaud/manage-distinct-profiles-in-git-1b56</guid>
      <description>&lt;p&gt;Original article in French on &lt;a href="https://gastaud.io/article/git-gerer-profils/"&gt;my blog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You use your computer to work and, more than ever, you probably use Git (what would you do on this article if not?).&lt;br&gt;&lt;br&gt;
Perhaps you also work on a personal project on the same computer?&lt;br&gt;&lt;br&gt;
Or to contribute to an Open-Source project, always on the same machine.&lt;/p&gt;

&lt;p&gt;You have probably defined a global identity (name + email) for your machine and overloaded it for each project according to the context.&lt;/p&gt;

&lt;p&gt;Perfect! Perfect!&lt;/p&gt;

&lt;p&gt;And yet despite these usual precautions, who has never commited in a project with a wrong identity?&lt;br&gt;
Sometimes you may find this out late and your personal email is now &lt;em&gt;ad vitam æternam&lt;/em&gt; in the project logs.&lt;/p&gt;

&lt;p&gt;So how can we try to limit the risk of errors?&lt;/p&gt;

&lt;p&gt;Could we automate the selection of the right identity for our projects?&lt;/p&gt;

&lt;p&gt;Well, the good news is that &lt;strong&gt;the answer is YES&lt;/strong&gt; and we'll see how right after that.&lt;/p&gt;
&lt;h2&gt;
  
  
  .gitconfig and conditional includes thanks to IncludeIf
&lt;/h2&gt;

&lt;p&gt;Let's take the file &lt;code&gt;.gitconfig&lt;/code&gt;, usually present in your &lt;code&gt;$HOME&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[user]
    name = Jean-Yves Gastaud
    email = mon.super@mail.com

[alias]
  amend = commit --amend
  st = status
  co = checkout
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This file defines our default identity and global aliases.&lt;/p&gt;

&lt;p&gt;Thanks to the use of the &lt;code&gt;includeIf&lt;/code&gt;&lt;sup id="fnref1"&gt;1&lt;/sup&gt; directive in our &lt;code&gt;.gitconfig&lt;/code&gt; file, we can now add conditional includes linked, especially to directories.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[includeIf "gitdir:/workspace/work/"]
  path = ~/.gitconfig-work

[includeIf "gitdir:/workspace/opensource/"]
  path = ~/.gitconfig-opensource

[includeIf "gitdir:/workspace/perso/"]
  path = ~/.gitconfig-perso
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For each defined &lt;code&gt;includeIf&lt;/code&gt;, all we have to do is create the file corresponding to the path we defined in &lt;code&gt;path&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;~/.gitconfig-work&lt;/code&gt; file, we only have to add or override the configurations we are interested in.&lt;/p&gt;

&lt;p&gt;Example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[user]
        email = my.work@mail.com

[core]
        editor = "code -w"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this file, we overload our email and add a default code editor.&lt;/p&gt;

&lt;p&gt;Now, any folder under the &lt;code&gt;/workspace/work&lt;/code&gt; directory will automatically benefit from loading the configuration of the &lt;code&gt;.gitconfig&lt;/code&gt; file, overloading or supplementing with those of the &lt;code&gt;.gitconfig-work&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;To check your configuration, go to any directory under the target directory, &lt;code&gt;/workspace/work&lt;/code&gt; in our example and run the command &lt;code&gt;git config -l&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should see the merging of your config files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user.name=Jean-Yves Gastaud
email = my.super@mail.com
alias.amend=commit --amend
alias.st=status
alias.co=checkout
includeif.gitdir:/workspace/work/work/.path=~/.gitconfig-work
user.email=my.work@mail.com
core.editor=code -w
includeif.gitdir:/workspace/opensource/.path=~/.gitconfig-opensource
includeif.gitdir:/workspace/perso/.path=~/.gitconfig-perso
core.repositoryformatversion=0
core.filemode=true
…
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see, the 2 defined emails are present in the listing.&lt;br&gt;&lt;br&gt;
The last "speaking" being right, it is therefore the value of the file &lt;code&gt;.gitconfig-work&lt;/code&gt; which will be considered during the commit.&lt;/p&gt;

&lt;p&gt;You will also notice that the other 2 include are listed but do not add new variables / overloads because their application condition is not met.&lt;/p&gt;

&lt;p&gt;This always gives us the possibility to overload, locally at the repository, all desired configurations, as before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In a few lines and a simple management of your working directories, it is therefore possible for you to no longer risk making mistakes in changing your identities.&lt;/strong&gt;&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;Since Git, version 2.13 (2017, May). &lt;a href="https://git-scm.com/docs/git-config#_includes"&gt;Documentation on Includes in Git&lt;/a&gt; ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>git</category>
      <category>tips</category>
      <category>profile</category>
      <category>configuration</category>
    </item>
  </channel>
</rss>
