David's public blog

Last month I have been using a codeblock hook to show scores using hugo. While it works, passing parameters in codeblocks is a pain.

I decided to convert it to a better system, i.e. shortcode, with lots of options. Still using OSMD as the display source

You can easily add the shortcode by adding it as a submodule. You can see the code here on (Github)[https://github.com/davidissamattos/hugo-musicxml-shortcode]:

  1. Navigate to your Hugo site’s root directory
  2. Add the shortcode as a submodule in the themes directory:
    git submodule add https://github.com/davidissamattos/hugo-musicxml-shortcode.git themes/hugo-musicxml-shortcode
    
  3. Update your site’s config.toml or config.yaml to include the theme:
    theme = ["hugo-musicxml-shortcode", "your-main-theme"]
    
  4. Initialize and update submodules when cloning your site repository:
    git submodule init
    git submodule update
    

Usage

In terms, of usage it is quite straight forward, see an example:

{{< musicxml
      title="Solo feature"
      file="/music/robin_adair.musicxml"
>}}
{{< /musicxml >}}

This is rendered like this: with a fold down preview that you can expand

Expand preview

But we can add many other options, like subset measures, parts, preview, fold, hide composer and title. The example below shows only measures 5-10 hides the composer and title, does not show the folding option nor the preview when it is folded

{{< musicxml
    title="Solo feature"
    file="/music/robin_adair.musicxml"
    preview="false"
    fold="false"
    hideComposer="true"
    hideTitle="true"
    fromMeasure="5"
    toMeasure="10"
>}}
{{< /musicxml >}}

We can also remove the flat icon if that is desired. See below the complete list of options

Parameters

All boolean-like parameters treat false, 0, no, or off (case-insensitive) as false. Any other value is treated as true.

ParameterTypeDefaultDescription
filestringPath to the MusicXML file to load. Required unless inline content is provided inside the shortcode.
titlestring"View full score"Title shown above the metadata panel and used for the Flat.io link.
previewbooltrueEnables the small preview excerpt inside the <summary>.
previewMeasuresnumber4Number of measures to show in the preview excerpt (still clamped by toMeasure).
foldbooltrueWraps the viewer in a <details> so the score can be collapsed.
flatbooltrueShows the “Add to Flat” link when a file is provided.
hideTitleboolfalseHides the score title in the full OSMD rendering.
hideComposerboolfalseHides composer and lyricist labels in both preview and full renderings.
hidePartNameboolfalseHides the part/staff labels on the score.
partstring or comma-separated listall partsLimits rendering to specific parts. Match by part name or MusicXML part ID. Example: part="Solo Cornet,Horn"
fromMeasurenumber1First measure to draw in both preview and full score.
toMeasurenumberlast measureFinal measure to draw. Omit or set < 1 to show the complete score.

#Hugo #Music #Osmd #Hugo-Shortcode