Skip to content

Including Remote Source code in Markdown file #2862

Answered by pdehaan
VaclavElias asked this question in Q&A
Discussion options

You must be logged in to vote

Maybe this?

eleventyConfig.addAsyncShortcode("remote_include", async function (urlPath) {
  const DOMAIN = "https://raw.githubusercontent.com/stride3d/stride/"
  if (urlPath.startsWith("/")) {
    // Make sure the `urlPath` doesn't start with `/` otherwise it will remove
    // the GitHub repo org/name from the path.
    urlPath = urlPath.slice(1);
  }
  const url = new URL(urlPath, DOMAIN).href;
  const sample = await EleventyFetch(url, {
    duration: "1d",
    type: "cs",
  });

  return sample;
});

USAGE

NOTE: I used an index.md file (w/ default LiquidJS templating)

---
title:  C# code reference in 11ty
description: Referencing C# code in 11ty
categories: dotnet
date: 2022-12-19
tags:…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@VaclavElias
Comment options

Answer selected by VaclavElias
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants