private static string GetRelativeResourceKey(string templateName, string relativePath) { if (string.IsNullOrEmpty(templateName)) { return(relativePath); } // Make sure resource keys are combined using '/' return(TypeForwardedToStringExtension.ForwardSlashCombine(TypeForwardedToStringExtension.ToNormalizedPath(Path.GetDirectoryName(templateName)), relativePath)); }
public override Stream GetResourceStream(string name) { if (IsEmpty) { return(null); } // incase relative path is combined by backslash \ if (!Names.Contains(TypeForwardedToStringExtension.ToNormalizedPath(name.Trim()), ResourceComparer)) { return(null); } var filePath = Path.Combine(_directory, name); return(new FileStream(filePath, FileMode.Open, FileAccess.Read)); }
private Manifest BuildCore(DocumentBuildParameters parameters) { using (new LoggerPhaseScope(PhaseName, true)) { Logger.LogInfo($"Max parallelism is {parameters.MaxParallelism}."); Directory.CreateDirectory(parameters.OutputBaseDir); var context = new DocumentBuildContext( Path.Combine(Directory.GetCurrentDirectory(), parameters.OutputBaseDir), parameters.Files.EnumerateFiles(), parameters.ExternalReferencePackages, parameters.XRefMaps, parameters.MaxParallelism, parameters.Files.DefaultBaseDir); if (ShouldTraceIncrementalInfo) { context.IncrementalBuildContext = IncrementalBuildContext.Create(parameters, CurrentBuildInfo, LastBuildInfo, IntermediateFolder); Logger.RegisterListener(context.IncrementalBuildContext.CurrentBuildVersionInfo.BuildMessage.GetListener()); if (context.IncrementalBuildContext.CanVersionIncremental) { context.IncrementalBuildContext.LoadChanges(); Logger.LogVerbose($"Before expanding dependency before build, changes: {JsonUtility.Serialize(context.IncrementalBuildContext.ChangeDict, Formatting.Indented)}"); var dependencyGraph = context.IncrementalBuildContext.LastBuildVersionInfo.Dependency; context.IncrementalBuildContext.ExpandDependency(dependencyGraph, d => dependencyGraph.DependencyTypes[d.Type].Phase == BuildPhase.Build || dependencyGraph.DependencyTypes[d.Type].TriggerBuild); Logger.LogVerbose($"After expanding dependency before build, changes: {JsonUtility.Serialize(context.IncrementalBuildContext.ChangeDict, Formatting.Indented)}"); } } Logger.LogVerbose("Start building document..."); // Start building document... List <HostService> hostServices = null; try { using (var templateProcessor = parameters.TemplateManager?.GetTemplateProcessor(context, parameters.MaxParallelism) ?? TemplateProcessor.DefaultProcessor) { IMarkdownService markdownService; using (new LoggerPhaseScope("CreateMarkdownService", true)) { markdownService = CreateMarkdownService(parameters, templateProcessor.Tokens.ToImmutableDictionary()); } using (new LoggerPhaseScope("Load", true)) { hostServices = GetInnerContexts(parameters, Processors, templateProcessor, markdownService, context).ToList(); } var manifest = BuildCore(hostServices, context, parameters.VersionName).ToList(); // Use manifest from now on using (new LoggerPhaseScope("UpdateContext", true)) { UpdateContext(context); } // Run getOptions from Template using (new LoggerPhaseScope("FeedOptions", true)) { FeedOptions(manifest, context); } // Template can feed back xref map, actually, the anchor # location can only be determined in template using (new LoggerPhaseScope("FeedXRefMap", true)) { FeedXRefMap(manifest, context); } using (new LoggerPhaseScope("UpdateHref", true)) { UpdateHref(manifest, context); } // Afterwards, m.Item.Model.Content is always IDictionary using (new LoggerPhaseScope("ApplySystemMetadata", true)) { ApplySystemMetadata(manifest, context); } // Register global variables after href are all updated IDictionary <string, object> globalVariables; using (new LoggerPhaseScope("FeedGlobalVariables", true)) { globalVariables = FeedGlobalVariables(templateProcessor.Tokens, manifest, context); } // processor to add global variable to the model foreach (var m in templateProcessor.Process(manifest.Select(s => s.Item).ToList(), context, parameters.ApplyTemplateSettings, globalVariables)) { context.ManifestItems.Add(m); } return(new Manifest { Files = context.ManifestItems.ToList(), Homepages = GetHomepages(context), XRefMap = ExportXRefMap(parameters, context), SourceBasePath = TypeForwardedToStringExtension.ToNormalizedPath(EnvironmentContext.BaseDirectory) }); } } finally { if (hostServices != null) { foreach (var item in hostServices) { Cleanup(item); item.Dispose(); } } } } }
private Stream GetResourceStreamCore(string name) { // zip entry is case sensitive // incase relative path is combined by backslash \ return(_zipped.GetEntry(TypeForwardedToStringExtension.ToNormalizedPath(name.Trim()))?.Open()); }