Christian Heilmann

Author Archive

Adding GitHub repository info, pages links and latest commits to any page using github-include

Tuesday, August 22nd, 2023

GitHub is where code lives. You make your updates there, and in the case of frontend work, you can even host it in GitHub pages.

When I publish something, I write a blog post and often I put some of the code in the post. When feedback comes in about new features I update the code and then I dread to also update the blog post. So, instead, I wanted to find a way to offer a link to the GitHub repo that shows the main link, a link to the GitHub pages, and show the latest commits. This allows people to see what changed in the code without me changing the post.

To make this happen, I wrote github-include, a web component that allows you to add a link to a repo to your blog post. It then converts it to a card showing the main repo link, a link to the GitHub Pages demo and the last x commits.

For example, the following HTML code gets converted to the card shown as an image here:

<github-include commits="5" pages="&#x1f30d;" links="true">
    <a href="https://github.com/codepo8/mastodon-share">
       Mastodon Share
   </a>
</github-include>

Recording of the web component in action

By default, it detects the setting of your OS and displays either as a dark or a light theme. If you don’t want any styling at all, you can also use plain HTML instead of the web component:

<div class="github-include" 
     data-commits="5"
     data-pages="&#x1f30d;" 
     data-links="true">
  <a href="https://github.com/codepo8/mastodon-share">
  Mastodon Share
  </a>
</div>

You can see it in action on the demo page .

You can customise all the functionality and labels of the component using attributes. These are all documented in the README .

Adding a “share to mastodon” link to any web site – and here

Friday, August 18th, 2023

I just added a “share to mastodon” link to this bloh. Ages ago I added a “share to Twitter” link, as there is a URL you can send Tweet content to that works:

http://twitter.com/share?url={URL}&text={TEXT}?&via={TWITTER_HANDLE}

With Mastodon, it wasn’t as easy as it is a federated service and there is not one URL. So I had to find a way to ask people for their service URL, and then store it somehow.

I’ve seen quite a few solutions for this, but I really wanted a bare-bones one that you can style any way you want. So here’s mastodon-share for you.

Mastodon Share

In order to add a “share to mastodon” link, all you need to do is to add a link with the class “.mastodon-share” and include the script:

<a href="#" target="mastodon" class="mastodon-share" rel="noopener">
Share to Mastodon
</a>
<script src="mastodon-share.js"></script>

The script is ridiculously simple, if you check it out:

// Grab link from the DOM
const button = document.querySelector('.mastodon-share');
 
// When a user clicks the link
button.addEventListener('click', (e) => {
 
// If the user has already entered their instance and it is in localstorage
// write out the link href with the instance and the current page title and URL
if(localStorage.getItem('mastodon-instance')) {
  button.href = `
    https://${localStorage.getItem('mastodon-instance')}/
    share?text=${encodeURIComponent(document.title)}
    %0A${encodeURIComponent(location.href)}
  `;
// otherwise, prompt the user for their instance and save it to localstorage
} else {
    e.preventDefault();
    let instance = window.prompt(
      'Please tell me your Mastodon instance'
    );
    localStorage.setItem('mastodon-instance', instance);
}
});

(yes, the comments were generated by GitHub CoPilot).

You can try it out on GitHub .

On my blog, I use WordPress and thus wanted to make the links also work when JavaScript fails for some reason, so I am using a slightly different approach. The PHP is:

<p class="mastodonshare">
  <a class="tootshare" 
     href="https://mastodon.social/share?text=<?php 
            echo get_the_title().' '.
            urlencode(the_permalink());
     ?>" target="blank" rel="noreferrer noopener">
       Share on Mastodon <span>(needs instance)</span>
  </a>
</p>

In the JavaScript, I also remove the span once the instance is stored in LocalStorage:

const button = document.querySelector('.tootshare');
    let key = 'mastodon-instance';
    let prompt = 'Please tell me your Mastodon instance';
 
    if(localStorage.getItem(key)) {
        button.querySelector('span').remove();
    }
 
    button.addEventListener('click', (e) => {
    if(localStorage.getItem(key)) {
    button.href = button.href.replace(
        "mastodon.social", 
        localStorage.getItem(key)
    );
 
    } else {
        e.preventDefault();
        let instance = window.prompt(prompt);
        localStorage.setItem(key, instance);
        button.querySelector('span').remove();
    }
});

Hope that helps!

I also came across the mastodon-share button by grayleonard that uses an input field on the button to allow you to specify the instance, but doesn’t store it. It looks nicer, though.

You can also use toot.kytta.dev to avoid having to request the mastodon instance people want to use, but I didn’t want to rely on another service.

What’s my job in my new role as Director of DevRel at WeAreDevelopers?

Wednesday, August 16th, 2023

Now, with the World Congress out of the way, it is time to focus on my new role as Director of Developer Relations at WeAreDevelopers.
It feels great that what I do anyways because of personal interest is part of my role. This was the case when I worked for Yahoo and Mozilla and the first few years in Microsoft, but pivoting to Technical Product Management, I was missing this part. I had to take vacation days to present at events and there was no budget for any DevRel activitives.

Now, what am I going to do for WeAreDevelopers? I will be leading and coaching a team of DevRel people and whilst this is small for now, there is growth in the near future.

For now, I will be:

  • Content editor of the DevDigest newsletter and blog and see what else we can do with that.
  • Recording interviews and fireside chats with interesting people in the Coffee with Developers series.
  • On the advirsory board for the WeAreDevelopers World Congress and plan the content of this 12,000 people event.
  • Keep evolving the Code100 competition and how we can make this easier to run, so that other events can also take part.
  • Working on some event strategy that goes beyond the big congress, with Bits and Bites meetups and a the WeAreDevelopers Live series.
  • Presenting at events, doing training courses and coach and mentor people inside and outside on public speaking, video creation, writing and presenting.

As WeAreDevelopers is also a job board, I also want to work closely with our recruiters and content editors to ensure that developers and those trying to hire developers speak the same language.

For all of this, I’d love input from you. You can:

  • Propose content items to write about and include in the newsletter
  • Propose people to interview
  • Tell me what a unique product like WeAreDevelopers can do to become your go-to resource for all things developer

Ping me on any of the channels I am on, or send content ideas to content@wearedevelopers.com

I’m looking forward to what comes next!

The Verge’s new way to display news item links is a terrible idea

Monday, August 14th, 2023

The game character Link from the Zelda games standing on a mystery box with question marks around.

Sometimes it is baffling to me why people publish on the web and don’t follow the simplest ideas that made the web what it is. Take a link for example. You can link anything in HTML so that when users interact with it they go to another URL, or a target inside the current document.

Links should do two things:

  • Tell you where they are going
  • Work for everyone

HTML links using the anchor element are amazingly accessible. They can be activated using mouse or keyboard, you can open the context menu on them and open them in a new tab, copy the link’s URL or bookmark them.

It is also immensely important that the link has some text and that this text is unique. The reason is that people who rely on assistive technology like screenreaders will access links outside of context.

Imagine that you can’t see and you want to quickly navigate a document without having to wait for the computer to read it all out to you. Screenreaders give you that option by offering the heading structure of a document and a list of landmarks in the document. Another fast way of navigating inside the document is getting a list of all the links in the document. According to WebAIM’s screen reader survey 67.7% of screenreader users navigate the document by skipping from heading to heading. 7.1% navigate via links and 8.1% read the whole document.

This weekend the Verge announced a new series on their magazine called The Installer, a newsletter that is also a web page. What a shocking new idea. What really baffled me though is that they chose to use a new way to display links that are part of the news announcement. And they chose one that breaks every link convention and represents an accessibility nightmare.

A paragraph of the newsletter blog post showing all content items as bold text followed by the word link in parenthesis

As explained in the screenshot, the installer displays news items as bold and not linked. Instead, each of the items is followed by the text “link” inside parenthesis. Why? Don’t know. What I do know though is that this means non-sighted people who’d love to consume the newsletter quickly and navigate only the links will get a list of items called “link” – and nothing else. Instead of getting a list of items to try out – the reason for the newsletter – they get a surprise every time they activate one of the links. Even without going through the links list but using the tab key to go through them with a screenreader enabled it’s easy to realise that this is an issue. Check out the following screen recording.

Isn’t it great that the email link and the subscribe link tell me what to do?

Sadly, this problem isn’t uncommon. WebAIM checks the accesssibility of the one million most used web sites every year. And the result is that 17.3% of pages had ambiguous link text like “click here”, “continue” and similar ones that only make sense in context and otherwise are just a nuisance. Image you are lost in a huge department store and you see arrows pointing down to the ground everywhere telling you that “you are here”.

I am not saying that all links should be blue and underlined (or purple when they are visited), although there are good reasons for that, too, but I am simply baffled how the most natural thing that makes the web work – the link – is still something people keep trying to reinvent instead of just using what works.

Do you want to be inclusive and reach the largest possible number of readers out there? Use headings, use links that are unique and write sensible alternative text for all images you use. It isn’t magic, it’s common sense.

Hey du da, im Radio… Interview mit Christian Heilmann im Deutschlandfunk über KI und Softwareentwicklung

Thursday, August 10th, 2023

Letzte Woche hatte ich ein Interview mit einem Redakteur vom Deutschlandfunk zum Thema “KI und Softwareentwicklung” und am letzten Samstag lief der Beitrag im Radio. Hier gibt es die online version .

Ich bin zufrieden mit dem Ergebnis, ausser das der O-Ton das 90% der Software bald von Software geschrieben wird nicht von mir stammt sondern von Thomas Dohmke, CEO von GitHub .