Ejemplo n.º 1
0
        /// <summary>
        ///     Invokes the plugin.
        /// </summary>
        ///
        /// <param name="project">
        ///     The `MetalsharpProject` to invoke the plugin on.
        /// </param>
        public void Execute(MetalsharpProject project)
        {
            foreach (var file in project.InputFiles)
            {
                if (file.Extension == ".md" || file.Extension == ".markdown")
                {
                    var fileText = Markdig.Markdown.ToHtml(file.Text);
                    var filePath = Path.Combine(file.Directory, file.Name + ".html");

                    project.OutputFiles.Add(new MetalsharpFile(fileText, filePath)
                    {
                        Metadata = file.Metadata
                    });
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Invokes the plugin.
 /// </summary>
 ///
 /// <param name="project">
 ///     The `MetalsharpProject` to invoke the plugin on.
 /// </param>
 public void Execute(MetalsharpProject project)
 {
     foreach (var file in project.InputFiles)
     {
         if (TryGetFrontmatter(file.Text, out Dictionary <string, object> metadata, out string text))
         {
             file.Text = text;
             foreach (var pair in metadata)
             {
                 if (file.Metadata.ContainsKey(pair.Key))
                 {
                     file.Metadata[pair.Key] = pair.Value;
                 }
                 else
                 {
                     file.Metadata.Add(pair.Key, pair.Value);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Invoke the Collections plugin with a single collection definition.
 /// </summary>
 ///
 /// <example>
 ///     Only add `.md` files to a collection named `myCollection`:
 ///
 ///     ```c#
 ///         new MetalsharpProject()
 ///         .UseCollections("myCollection", file => file.Extension == ".md");
 ///     ```
 /// </example>
 ///
 /// <param name="project">
 ///     The `MetalsharpProject` on which this method will be called.
 /// </param>
 /// <param name="name">
 ///     The name of the collection to define.
 /// </param>
 /// <param name="predicate">
 ///     The predicate to match the files for the collection.
 /// </param>
 ///
 /// <returns>
 ///     Combinator; returns `this` input.
 /// </returns>
 public static MetalsharpProject UseCollections(this MetalsharpProject project, string name, Predicate <IMetalsharpFile> predicate) =>
 project.Use(new Collections(name, predicate));
Ejemplo n.º 4
0
 /// <summary>
 ///     Invoke the Branch plugin.
 /// </summary>
 ///
 /// <example>
 ///     Branch the `MetalsharpProject` twice:
 ///
 ///     ```c#
 ///         new MetalsharpProject()
 ///         // Add files
 ///         .Branch(
 ///         dir => {
 ///         // Do something with branch 1
 ///         },
 ///         dir => {
 ///         // Do something with branch 2
 ///         }
 ///         );
 ///     ```
 /// </example>
 ///
 /// <param name="project">
 ///     The `MetalsharpProject` on which this method will be called.
 /// </param>
 /// <param name="branches">
 ///     The functions to handle each of the branches.
 /// </param>
 ///
 /// <returns>
 ///     Combinator; returns `this` input.
 /// </returns>
 public static MetalsharpProject Branch(this MetalsharpProject project, params Action <MetalsharpProject>[] branches) =>
 project.Use(new Branch(branches));
Ejemplo n.º 5
0
 /// <summary>
 ///     Invoke the Collections plugin with several collection definitions
 /// </summary>
 ///
 /// <example>
 ///     Add `.md` files to a collection named `mdFiles` and `.html` files to a collection named `htmlFiles`:
 ///
 ///     ```c#
 ///         new MetalsharpProject()
 ///         .UseCollections(("mdFiles", file => file.Extension == ".md"), ("htmlFiles", file => file.Extension == ".html"));
 ///     ```
 /// </example>
 ///
 /// <param name="project">
 ///     The `MetalsharpProject` on which this method will be called.
 /// </param>
 /// <param name="definitions">
 ///     The definitions of each collection.
 /// </param>
 ///
 /// <returns>
 ///     Combinator; returns `this` input.
 /// </returns>
 public static MetalsharpProject UseCollections(this MetalsharpProject project, params (string name, Predicate <IMetalsharpFile> predicate)[] definitions) =>