<?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>Forem: hedy</title>
    <description>The latest articles on Forem by hedy (@hedyhli).</description>
    <link>https://forem.com/hedyhli</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%2F314185%2F0bed9a10-936b-414b-afc4-615adb897984.jpg</url>
      <title>Forem: hedy</title>
      <link>https://forem.com/hedyhli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hedyhli"/>
    <language>en</language>
    <item>
      <title>Setting up syntax highlighting for Hugo</title>
      <dc:creator>hedy</dc:creator>
      <pubDate>Sun, 22 Aug 2021 00:00:00 +0000</pubDate>
      <link>https://forem.com/hedyhli/setting-up-syntax-highlighting-for-hugo-ae</link>
      <guid>https://forem.com/hedyhli/setting-up-syntax-highlighting-for-hugo-ae</guid>
      <description>&lt;p&gt;Cross-posted from: &lt;a href="https://hedy.tilde.cafe/posts/hugo-syntax-highlighting/" rel="noopener noreferrer"&gt;https://hedy.tilde.cafe/posts/hugo-syntax-highlighting/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;--&lt;/p&gt;

&lt;p&gt;Hugo uses &lt;a href="https://github.com/alecthomas/chroma" rel="noopener noreferrer"&gt;chroma&lt;/a&gt; as its syntax highlighter, and it’s mostly compatible with pygments. All you basically need for having your code highlighted is to let chroma put the syntax classes in the generated HTML, for the correct language, and then make sure you have corresponding CSS for those classes.&lt;/p&gt;

&lt;p&gt;Let’s start by enabling syntax highlighting in your configuration file.&lt;/p&gt;

&lt;p&gt;In your configuration file, &lt;code&gt;config.toml&lt;/code&gt; for example, add these settings so you can have your code highlighted and have it recognize Fenced Code Blocks for markdown:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="py"&gt;pygmentsUseClasses&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="py"&gt;pygmentsCodeFences&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next you have to include the styles. There are two ways to go about this, one is to choose a style from the list of available styles (more on that below), and the second method is to use your own syntax theme.&lt;/p&gt;

&lt;p&gt;You can have your own CSS styles, but there are &lt;em&gt;a lot&lt;/em&gt; of classes, so if you’re just starting out and want to have it working quickly, you should choose an existing style.&lt;/p&gt;

&lt;p&gt;Browse the &lt;a href="https://xyproto.github.io/splash/docs/" rel="noopener noreferrer"&gt;gallery&lt;/a&gt; of available styles and use that style name to save the CSS file into your &lt;code&gt;assets&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p assets/syntax
hugo gen chromastyles --style=friendly &amp;gt; assets/syntax/main.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you’d like to use different styles for dark mode and light mode (like me), then you can change “main.css” to “light.css”, and save the dark mode style to “dark.css”. It doesn’t matter where you put the file, but just remember to use that file name with referencing it later.&lt;/p&gt;

&lt;p&gt;You don’t have to put it under the directory “syntax” too, if you don’t want to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Apply the styles
&lt;/h2&gt;

&lt;p&gt;You have to link to your CSS file that you’ve just created in your &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;. There are several ways you can do so.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use a &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag and link to the URL of your CSS file, or&lt;/li&gt;
&lt;li&gt;directly put the content of your file into a &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s how you can do the second method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;{{- $syntaxCSS := resources.Get "syntax/main.css" | minify -}}
&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="err"&gt;$syntaxCSS.Content&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="err"&gt;safeCSS&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assuming your CSS file is at &lt;code&gt;assets/syntax/main.css&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;All set for the styling part! Now you can write some content and try it out.&lt;/p&gt;

&lt;p&gt;Remember to include the file type when putting code in markdown.&lt;/p&gt;

&lt;pre&gt;This is not sh


```sh
# this is sh
echo "hi"
```

&lt;/pre&gt;

&lt;h2&gt;
  
  
  Dark mode and light mode
&lt;/h2&gt;

&lt;p&gt;You can have different styles of syntax highlighting for dark mode and light mode.&lt;/p&gt;

&lt;p&gt;First you have to export or save your CSS for dark mode and light mode in separate files . Then, change the part in your &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; where you’ve included the styles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;{{- $syntaxlight := resources.Get "syntax/light.css" | minify -}}
{{- $syntaxdark := resources.Get "syntax/dark.css" | minify -}}
&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="err"&gt;$syntaxlight.Content&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="err"&gt;safeCSS&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-color-scheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;dark&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="err"&gt;$syntaxdark.Content&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="err"&gt;safeCSS&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This assumes you have your light styles and dark mode styles stored in&lt;code&gt;assets/syntax/light.css&lt;/code&gt; and &lt;code&gt;assets/syntax/dark.css&lt;/code&gt; respectively.&lt;/p&gt;

&lt;p&gt;Instead of doing the above, you could have just put both in a single file and include the &lt;code&gt;@media (prefers-color-scheme: dark)&lt;/code&gt; line in there directly, and this won’t require you to change your &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; at all. And of course you could have just used CSS variables and store the theme’s colors into different variables, use &lt;code&gt;var(--variable-name)&lt;/code&gt; for each class in the styles, and finally have a different set up variable values for &lt;code&gt;@media (prefers-color-scheme: dark) {}&lt;/code&gt;. But using the method of separating dark and light styles has the advantage of changing the themes for light or dark mode in the future with the&lt;code&gt;chroma&lt;/code&gt; command and pipe it to the file directly, without having to edit the CSS file by hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applying syntax highlight CSS file only when it’s needed
&lt;/h2&gt;

&lt;p&gt;Fetching syntax highlighting theme and putting it in your &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; means that every single page would have the syntax highlighting CSS code in the page, regardless of whether the page actually uses it. If you’d like to only include the syntax CSS files for pages that needs syntax highlighting, you can use a page parameter named something like &lt;code&gt;highlight&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here’s how it would work.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set a &lt;code&gt;highlight&lt;/code&gt; param in your global config file that is set to false by default&lt;/li&gt;
&lt;li&gt;For each post or page in your &lt;code&gt;content/&lt;/code&gt; that needs syntax highlighting, include &lt;code&gt;highlight: true&lt;/code&gt;in the frontmatter (assuming you’re using YAML).&lt;/li&gt;
&lt;li&gt;In &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;, check whether the page’s &lt;code&gt;highlight&lt;/code&gt; param is set to true, and only if it’s true, the CSS resource is loaded.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In your &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;, include this before fetching the CSS resource, and put&lt;code&gt;{{ end }}&lt;/code&gt; after &lt;code&gt;&amp;lt;/style&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;{{- if .Params.highlight -}}
&lt;span class="c"&gt;&amp;lt;!--Put the code that fetches your syntax highlight CSS here--&amp;gt;&lt;/span&gt;
{{- end -}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells hugo to only load the resource and put the CSS in &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; if the page parameter&lt;code&gt;highlight&lt;/code&gt; is set to true.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read more
&lt;/h2&gt;

&lt;p&gt;There are many configuration options for syntax highlighting, read this page on Hugo docs for more information: &lt;a href="https://gohugo.io/getting-started/configuration-markup#highlight" rel="noopener noreferrer"&gt;gohugo.io/getting-started/configuration-markup#highlight&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’d like to highlight specific lines in code snippets, you can read about how to do that here: &lt;a href="https://gohugo.io/content-management/syntax-highlighting/#example-highlight-shortcode" rel="noopener noreferrer"&gt;gohugo.io/content-management/syntax-highlighting/#example-highlight-shortcode&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is also a &lt;code&gt;highlight&lt;/code&gt; shortcode shipped with Hugo that lets you manually highlight code with chroma: &lt;a href="https://gohugo.io/content-management/shortcodes/#highlight" rel="noopener noreferrer"&gt;gohugo.io/content-management/shortcodes/#highlight&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>hugo</category>
      <category>blog</category>
    </item>
    <item>
      <title>Managing multiple emails for git across different computers</title>
      <dc:creator>hedy</dc:creator>
      <pubDate>Wed, 16 Jun 2021 23:50:00 +0000</pubDate>
      <link>https://forem.com/hedyhli/managing-multiple-emails-for-git-across-different-computers-12f</link>
      <guid>https://forem.com/hedyhli/managing-multiple-emails-for-git-across-different-computers-12f</guid>
      <description>&lt;p&gt;Cross-posted from: &lt;a href="https://hedy.tilde.cafe/posts/multiple-emails-git/"&gt;https://hedy.tilde.cafe/posts/multiple-emails-git/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;As someone who code on multiple machines to work on different projects, I like to commit with different emails.&lt;/p&gt;

&lt;p&gt;I don’t know how everyone else handle different emails in .gitconfig &lt;em&gt;and&lt;/em&gt; track dotfiles in a git repo at the same time, but here’s the solution I’ve come up with.&lt;/p&gt;

&lt;p&gt;First, I have a global ~/.gitconfig with the default user email and some other global settings (by global I mean same cross different computers I work on).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ~/.gitconfig
[user]
name = Default Name
email = me@default.email
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then for each machine I have a ~/.gitconfig-local file which can override some settings just for that machine, such as email, signing key, editor, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ~/.gitconfig-local
[user]
email = me@special.email
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Back in the global ~/.gitconfig, I have this snippet that tells git to also look for configuration in my ~/.gitconfig-local:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ~/.gitconfig
[include]
path = ~/.gitconfig-local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, I can have ~/.gitconfig tracked in my dotfiles repo, but I do not have ~/.gitconfig-local tracked. This way, I can put anything I like specific to a particular machine in the ~/.gitconfig-local, as well as SMTP settings such as password, which you wouldn’t want to end up in a public git repo.&lt;/p&gt;

&lt;p&gt;As to setting it up on a new machine, I have a setup script in my dotfiles repo that creates an empty ~/.gitconfig-local. I use this same method with fish configs – global config and a local config, you can have a look at them in my &lt;a href="https://github.com/hedyhli/dotfiles"&gt;dotfiles repo&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>git</category>
      <category>config</category>
    </item>
    <item>
      <title>Control the Probability of This GitHub Action from Passing/Failing</title>
      <dc:creator>hedy</dc:creator>
      <pubDate>Sat, 22 Aug 2020 04:47:48 +0000</pubDate>
      <link>https://forem.com/hedyhli/control-the-probability-of-this-github-action-from-passing-4j59</link>
      <guid>https://forem.com/hedyhli/control-the-probability-of-this-github-action-from-passing-4j59</guid>
      <description>&lt;p&gt;Just give it a percentage, say 50, and it will have a 50/50 chance of passing! Which means if you give it 0 or 10, it will fail all the time and most of the times respectively. 😏 Pretty cool right?&lt;/p&gt;

&lt;h3&gt;
  
  
  GitHub repo
&lt;/h3&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/hedyhli" rel="noopener noreferrer"&gt;
        hedyhli
      &lt;/a&gt; / &lt;a href="https://github.com/hedyhli/passibility" rel="noopener noreferrer"&gt;
        passibility
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      ✅ Control the probability of this Github action from passing/failing!
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;h3&gt;
  
  
  How to use this
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Will&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Pass..."&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;push&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hedythedev/passibility@main&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;percentage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example Workflow&lt;/strong&gt;: This workflow will pass all the time! &lt;/p&gt;

&lt;h3&gt;
  
  
  Option Inputs
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;percentage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Percentage of passing - (without the %) 0, for always fail, 100 for always pass and so on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional info
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This is my first GitHub action, and it’s written in JavaScript.&lt;/li&gt;
&lt;li&gt;Generated from the &lt;a href="https://github.com/actions/javascript-action" rel="noopener noreferrer"&gt;JavaScript Action Template&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Unit tests using Jest&lt;/li&gt;
&lt;li&gt;This isn’t a submission to the Actions Hackathon because I’m not old enough (18+ only), but I made this to experiment with GitHub Actions&lt;/li&gt;
&lt;li&gt;Feel free to try it out and give me some feedback&lt;/li&gt;
&lt;li&gt;Contributions welcome - like having another input called fail_percentage so you can instead provide the fail probability? 🤔&lt;/li&gt;
&lt;li&gt;Remember to ⭐ star the project if you liked it ;)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>github</category>
      <category>actions</category>
      <category>showdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
