public ContentPlugin(SiteObject site) : base(site) { previousOutputDirectories = new HashSet <DirectoryEntry>(); previousOutputFiles = new HashSet <FileEntry>(); Scripts = Site.Scripts; filesWritten = new Dictionary <FileEntry, FileEntry>(); totalDuration = new Stopwatch(); OrderLayoutTypes = new List <string>(); BeforeInitializingProcessors = new OrderedList <ISiteProcessor>(); BeforeLoadingProcessors = new OrderedList <ISiteProcessor>(); BeforeLoadingContentProcessors = new OrderedList <TryProcessPreContentDelegate>(); AfterLoadingProcessors = new OrderedList <ISiteProcessor>(); AfterRunningProcessors = new OrderedList <IContentProcessor>(); BeforeProcessingProcessors = new OrderedList <ISiteProcessor>(); ContentProcessors = new OrderedList <IContentProcessor>(); AfterProcessingProcessors = new OrderedList <ISiteProcessor>(); }
private static async Task <ContentObject> LoadPageScript(SiteObject site, Stream stream, FileEntry file) { // Read the stream var reader = new StreamReader(stream); var content = await reader.ReadToEndAsync(); // Early dispose the stream stream.Dispose(); ContentObject page = null; // Parse the page, using front-matter mode var scriptInstance = site.Scripts.ParseScript(content, file.FullName, ScriptMode.FrontMatterAndContent); if (!scriptInstance.HasErrors) { page = new ContentObject(site, file, scriptInstance); var evalClock = Stopwatch.StartNew(); if (site.Content.TryPreparePage(page)) { evalClock.Stop(); // Update statistics var contentStat = site.Statistics.GetContentStat(page); contentStat.EvaluateTime += evalClock.Elapsed; // Update the summary of the page evalClock.Restart(); SummaryHelper.UpdateSummary(page); evalClock.Stop(); // Update statistics contentStat.SummaryTime += evalClock.Elapsed; } } return(page); }
protected SitePluginCore(SiteObject site) { Site = site ?? throw new ArgumentNullException(nameof(site)); }
public LunetCommandLine(SiteObject site) : base(false) { if (site == null) { throw new ArgumentNullException(nameof(site)); } this.site = site; Name = "lunet"; FullName = "Lunet Static Website Engine"; Description = "LunetCommand to generate static website"; HandleResponseFiles = false; AllowArgumentSeparator = true; HelpOption("-h|--help"); var versionText = typeof(SiteObject).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version; var infoVersionText = typeof(SiteObject).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion; var version = VersionOption("-v|--version", versionText, infoVersionText); // The defines to setup before initializing config.sban Defines = Option("-d|--define <variable=value>", "Defines a site variable", CommandOptionType.MultipleValue); OutputDirectory = Option("-o|--output-dir <dir>", $"The output directory of the generated website. Default is '{SiteObject.DefaultOutputFolderName}'", CommandOptionType.SingleValue); InputDirectory = Option("-i|--input-dir <dir>", "The input directory of the website content to generate from. Default is '.'", CommandOptionType.SingleValue); this.Invoke = () => { if (!this.OptionHelp.HasValue() || !version.HasValue()) { this.ShowHint(); } if (RemainingArguments.Count > 0) { Reporter.Output.WriteLine($"Invalid command arguments : {string.Join(" ",RemainingArguments)}".Red()); return(1); } return(0); }; // New command InitCommand = Command("init", newApp => { newApp.Description = "Creates a new website"; var forceOption = newApp.Option("-f|--force", "Force the creation of the website even if the folder is not empty", CommandOptionType.NoValue); CommandArgument folderArgument = newApp.Argument("[folder]", "Destination folder. Default is current directory."); // TODO: List the supported type on --help -h newApp.HelpOption("-h|--help"); newApp.Invoke = () => { var inputFolder = folderArgument.Value ?? "."; if (InputDirectory.Values.Count > 0) { InputDirectory.Values[0] = inputFolder; } else { InputDirectory.Values.Add(inputFolder); } HandleCommonOptions(); try { site.Create(forceOption.HasValue()); return(0); } catch (Exception ex) { site.Error($"Unexpected exception while trying to copy files: {ex.GetReason()}"); return(1); } }; }, false); // New command NewCommand = Command("new", newApp => { newApp.Description = "Creates a new content for the website from an archetype"; CommandArgument typeArgument = newApp.Argument("<type>", "Type of the content to generate"); // TODO: List the supported type on --help -h newApp.HelpOption("-h|--help"); }, false); // config command ConfigCommand = Command("config", newApp => { newApp.Description = "Displays the configuration variables from an existing config or the defaults"; newApp.HelpOption("-h|--help"); }, false); // The run command RunCommand = Command("build", newApp => { newApp.Description = "Builds the website"; newApp.HelpOption("-h|--help"); newApp.Invoke = () => { HandleCommonOptions(); site.Build(); return(site.HasErrors ? 1 : 0); }; }, false); // The clean command CleanCommand = Command("clean", newApp => { newApp.Description = "Cleans temporary folder"; newApp.HelpOption("-h|--help"); newApp.Invoke = () => { HandleCommonOptions(); return(site.Clean()); }; }, false); }
protected ContentObject(SiteObject site, ContentObjectType objectType, FileEntry sourceFileInfo = null, ScriptInstance scriptInstance = null, UPath?path = null) : base(site, objectType, sourceFileInfo, scriptInstance, path) { // Default to single layout type LayoutType = "single"; }
protected SitePlugin(SiteObject site) : base(site) { }
public ContentObject(SiteObject site, FileEntry sourceFileInfo, ScriptInstance scriptInstance = null) { Site = site ?? throw new ArgumentNullException(nameof(site)); SourceFile = sourceFileInfo ?? throw new ArgumentNullException(nameof(sourceFileInfo)); FrontMatter = scriptInstance?.FrontMatter; Script = scriptInstance?.Template; Dependencies = new List <ContentDependency>(); ObjectType = ContentObjectType.File; // TODO: Make this part pluggable // Parse a standard blog text var match = ParsePostName.Match(sourceFileInfo.Name); if (match.Success) { var year = int.Parse(match.Groups[1].Value); var month = int.Parse(match.Groups[2].Value); var day = int.Parse(match.Groups[3].Value); var title = match.Groups[4].Value; Date = new DateTime(year, month, day); Title = StringFunctions.Capitalize(title.Replace('-', ' ')); } else { Date = DateTime.Now; } Path = sourceFileInfo.Path; Length = SourceFile.Length; Extension = SourceFile.ExtensionWithDot?.ToLowerInvariant(); ModifiedTime = SourceFile.LastWriteTime; ContentType = Site.ContentTypes.GetContentType(Extension); // Extract the section of this content Section = Path.GetFirstDirectory(out var pathInSection); if (pathInSection.IsEmpty) { Section = string.Empty; PathInSection = Path; } else { PathInSection = pathInSection; } Layout = Section; // Extract the default Url of this content // By default, for html content, we don't output a file but a directory var urlAsPath = (string)Path; var isHtml = Site.ContentTypes.IsHtmlContentType(ContentType); if (isHtml) { var name = Path.GetNameWithoutExtension(); var isIndex = name == "index"; if (isIndex) { urlAsPath = Path.GetDirectory().FullName + "/"; } else if (HasFrontMatter && !Site.UrlAsFile) { if (!string.IsNullOrEmpty(Extension)) { urlAsPath = urlAsPath.Substring(0, urlAsPath.Length - Extension.Length); } urlAsPath = PathUtil.NormalizeUrl(urlAsPath, true); } } Url = urlAsPath; // Replicate readonly values to the Scripting object InitializeReadOnlyVariables(); }
public static void Debug(this SiteObject site, SourceSpan span, string message, params object[] args) { site.Log.LogDebug(new EventId(site.LogEventId++), GetSpanMessage(site, span, message), args); }
private static string GetSpanMessage(SiteObject site, SourceSpan span, string message) { var fileRelative = span.FileName ?? string.Empty; return($"In {fileRelative}({span.Start.ToStringSimple()}): {message}"); }
public static void Fatal(this SiteObject site, string message, params object[] args) { site.Log.LogCritical(new EventId(site.LogEventId++), message, args); }
public static void Debug(this SiteObject site, string message, params object[] args) { site.Log.LogDebug(new EventId(site.LogEventId++), message, args); }
public static void Error(this SiteObject site, Exception exception, string message, params object[] args) { site.Log.LogError(new EventId(site.LogEventId++), exception, message, args); }
public static void Info(this SiteObject site, string message, params object[] args) { site.Log.LogInformation(new EventId(site.LogEventId++), message, args); }
public static bool CanInfo(this SiteObject site) { return(site.Log.IsEnabled(LogLevel.Information)); }
public static bool CanDebug(this SiteObject site) { return(site.Log.IsEnabled(LogLevel.Debug)); }
public static bool CanTrace(this SiteObject site) { return(site.Log.IsEnabled(LogLevel.Trace)); }