Getting the user's Mastodon-compatible username

I want to include this in the metadata.
I see mastodon in the parameters but it’s for the cross post mapping.

For example, I have @mandaris@mandarismoore.com in my settings and @mandaris@social.lol in my mapping.

Is this property exposed and I’m just not searching for it properly?

No, I don’t think the ActivityPub (Mastodon-compatible) username is exposed in Hugo templates, unfortunately. It is public information, however, so, in theory, you could fetch it from the user’s profile page using resources.GetRemote and findRE.

But that is a bit of a hack and would slow down builds. Hopefully, @manton will consider exposing the ActivityPub username to Hugo templates instead.

You can just add it to your config as a site level custom param. For example, this is my site’s config.json:

{
  "markup": {
    "highlight": {
      "anchorLineNos": false,
      "codeFences": true,
      "guessSyntax": true,
      "hl_Lines": "",
      "lineAnchors": "",
      "lineNoStart": 1,
      "lineNos": true,
      "lineNumbersInTable": true,
      "noClasses": true,
      "style": "dracula",
      "tabWidth": 4
    },
    "goldmark": {
      "renderer": {
        "unsafe": true
      }
    }
  },
  "params": {
    "twitter_username": "jsonbecker",
    "github_username": "jsonbecker",
    "instagram_username": "jsonbecker",
    "mastodon_url": "indieweb.social/@jsonbecker",
    "bookshop_affiliate_id": "9011",
    "contact": "hello@jbecker.co",
    "menu": [
      {
        "name": "Now",
        "url": "/categories/now"
      },
      {
        "name": "Books",
        "url": "/books"
      },
      {
        "name": "Photos",
        "url": "/categories/photoblogging"
      },
      {
         "name": "Archive",
         "url": "/archive"
      }
    ]
  }
}


Then you can use things like .Site.Params.github_username to access in a template.

1 Like

I’ll add it as a default parameter too.

2 Likes

Thank you.

Sometimes, I feel like an edge case for some of this stuff. I don’t want to ask for a change that is more work than it’s worth.

Please don’t hesitate to mention stuff like this that is missing. Sometimes it’s on purpose but often just an oversight, like in this case of the ActivityPub username. I’ll get it added within the next couple of days. Thanks!

I’m still running into issues with stuff like this. I would really appreciate it if things like menus and parameters were more user friendly.

When I attempt to add parameters like @jsonbecker describes, I see multiple copies of the config.json. Is this the right one? I don’t know, but I don’t see the changes in my final rendering.

Sorry. A little bit of a rant.

There should be only one copy in the top section of the custom design page that you edit. That’s the one that you’re using to add your own options. I would not look to mine for menus— I’m doing unique stuff for my menus. However, all things that are placed in the params map are accessible as .Site.params.$YOURKEYNAMEHERE.

These are not easy to make a menu— it’s literally an arbitrary data structure you can put whatever you want into that can be accessed by templates. There’s nothing special about it.

I feel that I’m getting what you are saying. I’m currently trying a set up where I use the plugin theme and then a custom theme called properties.

But I find that properties that I add do not show up in the final rendering.

It could just be me but it’s still very, very frustrating.

you can remove everything there that is in other versions of the config…

your config can just be:

{
  "params": {
    "contact": "info@mandarismoore.com"
  }
}

And then in your template use {{ .Site.Params.Contact }} to get that information.

All the stuff with [] around it is probably from the micro.blog level stuff and shouldn’t be in your custom config.json file.

For example, I used to have this in a theme:

 {{ if .Site.Params.Contact }}
       <li>
         <a href="mailto:{{ .Site.Params.Contact }}">Contact</a>
       </li>
{{ end }}

And that would show up only if I filled in the above like shown.

I think you’re way overcomplicating the theme setup. Use the plug in theme, then click “custom theme” then select the plug in theme you’re using. Edit only the config.json file under Custom templates. ONLY add the fields you want to add, don’t worry about what the theme version or Micro.blog version has. Anything in custom themes will be added to and override the same values in the theme config.json and the micro.blog config.json. You should never touch those nor do you need to copy those.

Just wanted to follow up to close the loop.

I was able to get it working today.

The only reason I was going down this path was that layouts/index.xml from the default theme had the following

{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}

It wasn’t populating and I thought I would give it the .Site.Author.email via the config.json.

I’m just going to drop it because I’m making this more complicated than it should be.