Exemplo n.º 1
0
        public ReleaseNotes()
        {
            DependencyOf.Add(nameof(Statiq.Web.Pipelines.Content));

            InputModules = new ModuleList
            {
                new ExecuteIf(Config.ContainsSettings("GITHUB_TOKEN"))
                {
                    new ReadGitHub(async(ctx, github) =>
                                   (await Projects.ToAsyncEnumerable().SelectManyAwait(x => GetReleaseNotesAsync(github, x)).ToArrayAsync())
                                   .ToDocuments(sourceFunc: x => ctx.FileSystem.RootPath / ctx.FileSystem.InputPaths[0] / $"news/posts/{x.Project}-{x.Name}.md", null))
                    .WithCredentials(Config.FromSetting <string>("GITHUB_TOKEN"))
                }
            };

            ProcessModules = new ModuleList
            {
                // Need to replace "@" for Razor and "<?" because some of the release notes reference shortcode syntax
                new SetContent(Config.FromDocument(doc => doc.GetString(nameof(ReleaseNote.Body)).Replace("@", "@@").Replace("<?", "&lt;?")), MediaTypes.Markdown),
                new SetMetadata(SiteKeys.Topic, Config.FromDocument(doc => "release")),
                new SetMetadata(Keys.Title, Config.FromDocument(doc => $"{doc[nameof(ReleaseNote.Project)]} Release {doc[nameof(ReleaseNote.Name)]}")),
                new SetDestination(Config.FromDocument(doc =>
                                                       new NormalizedPath($"news/{doc.GetDateTimeOffset(nameof(ReleaseNote.Published)):yyyy/MM/dd}/{doc[nameof(ReleaseNote.Project)]}-{doc[nameof(ReleaseNote.Name)]}.html")
                                                       .OptimizeFileName()))
            };
        }
Exemplo n.º 2
0
    public Api()
    {
        Dependencies.Add(nameof(Code));
        DependencyOf.Add(nameof(Content));

        ProcessModules = new ModuleList
        {
            new ConcatDocuments(nameof(Code)),
            new CacheDocuments(
                new AnalyzeCSharp()
                .WhereNamespaces(ns => ns.StartsWith("Spectre.Console") && !ns.Contains("Analyzer") &&
                                 !ns.Contains("Testing") && !ns.Contains("Examples"))
                .WherePublic(true)
                .WithCssClasses("code", "cs")
                .WithDestinationPrefix("api")
                .WithAssemblySymbols()
                .WithImplicitInheritDoc(false),
                new ExecuteConfig(Config.FromDocument((doc, ctx) =>
            {
                // Calculate a type name to link lookup for auto linking
                string name = null;

                var kind = doc.GetString(CodeAnalysisKeys.Kind);
                switch (kind)
                {
                case "NamedType":
                    name = doc.GetString(CodeAnalysisKeys.DisplayName);
                    break;

                case "Method":
                    var containingType = doc.GetDocument(CodeAnalysisKeys.ContainingType);
                    if (containingType != null)
                    {
                        name =
                            $"{containingType.GetString(CodeAnalysisKeys.DisplayName)}.{doc.GetString(CodeAnalysisKeys.DisplayName)}";
                    }
                    break;
                }

                if (name != null)
                {
                    var typeNameLinks = ctx.GetRequiredService <TypeNameLinks>();
                    typeNameLinks.Links.AddOrUpdate(WebUtility.HtmlEncode(name), ctx.GetLink(doc),
                                                    (_, _) => string.Empty);
                }

                // Add metadata
                var metadataItems = new MetadataItems
                {
                    { WebKeys.Xref, doc.GetString(CodeAnalysisKeys.CommentId) },
                    { WebKeys.Layout, "api/_layout.cshtml" },
                    { Constants.Hidden, true }
                };

                var contentProvider = doc.ContentProvider.CloneWithMediaType(MediaTypes.Html);
                metadataItems.Add(WebKeys.ContentType, ContentType.Content);
                return(doc.Clone(metadataItems, contentProvider));
            }))).WithoutSourceMapping()
        };
    }
Exemplo n.º 3
0
    public ExampleSyntax()
    {
        Dependencies.Add(nameof(ExampleCode));
        DependencyOf.Add(nameof(Content));

        ProcessModules = new ModuleList
        {
            new ConcatDocuments(nameof(Code)),
            new ConcatDocuments(nameof(ExampleCode)),
            new CacheDocuments(
                new AnalyzeCSharp()
                .WhereNamespaces(true)
                .WherePublic()
                .WithCssClasses("code", "cs")
                .WithDestinationPrefix("syntax")
                .WithAssemblySymbols()
                // we need to load Spectre.Console for compiling, but we don't need to process it in Statiq
                .WhereNamespaces(i => !i.StartsWith("Spectre.Console"))
                .WithImplicitInheritDoc(false),
                new ExecuteConfig(Config.FromDocument((doc, _) =>
            {
                // Add metadata
                var metadataItems = new MetadataItems
                {
                    // Calculate an xref that includes a "api-" prefix to avoid collisions
                    { WebKeys.Xref, "syntax-" + doc.GetString(CodeAnalysisKeys.CommentId) },
                };

                var contentProvider = doc.ContentProvider;
                return(doc.Clone(metadataItems, contentProvider));
            }))).WithoutSourceMapping()
        };
    }
Exemplo n.º 4
0
        /// <summary>
        /// takes a list of dependencies and returns their names sorted from least dependent to most
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="deps"></param>
        /// <returns></returns>
        public static List <NamedDependency> Sort(List <NamedDependency> deps)
        {
            if (deps == null)
            {
                return(null);
            }

            List <DependencyOf <string> > items = new List <DependencyOf <string> >();

            items.AddRange(deps);
            var sortedStrings = DependencyOf <string> .Sort(items);

            List <NamedDependency> returnValue = new List <NamedDependency>();

            sortedStrings.WithEach(x =>
            {
                returnValue.Add(deps.SingleOrDefault(y => y.Self == x));
            });
            return(returnValue);
        }