Example #1
0
    public async Task PrerenderMarkdown()
    {
        var srcDir = WwrootDir.CombineWith("content").Replace('\\', '/');
        var dstDir = WwrootDir.CombineWith("docs").Replace('\\', '/');

        var indexPage = PageTemplate.Create(WwrootDir.CombineWith("index.html"));

        if (!Directory.Exists(srcDir))
        {
            throw new Exception($"{Path.GetFullPath(srcDir)} does not exist");
        }
        FileSystemVirtualFiles.RecreateDirectory(dstDir);

        foreach (var file in new DirectoryInfo(srcDir).GetFiles("*.md", SearchOption.AllDirectories))
        {
            WriteLine($"Converting {file.FullName} ...");

            var name      = file.Name.WithoutExtension();
            var docRender = await Client.MarkdownUtils.LoadDocumentAsync(name, doc =>
                                                                         Task.FromResult(File.ReadAllText(file.FullName)));

            if (docRender.Failed)
            {
                WriteLine($"Failed: {docRender.ErrorMessage}");
                continue;
            }

            var dirName = dstDir.IndexOf("wwwroot") >= 0
                ? dstDir.LastRightPart("wwwroot").Replace('\\', '/')
                : new DirectoryInfo(dstDir).Name;
            var path = dirName.CombineWith(name == "index" ? "" : name);

            var    mdBody          = @$ "
<div class=" "prose lg:prose-xl min-vh-100 m-3" " data-prerender=" "{path}" ">
Example #2
0
 public PageTemplate NewPageTemplateProperties(int parentId) => PageTemplate.Create(parentId, SiteRepository.GetById(parentId));