private IDocument GenerateFeed(FeedType feedType, Feed feed, ContextConfig path, IExecutionContext context) { // Get the output path FilePath outputPath = path?.Invoke <FilePath>(context, "while getting output path"); if (outputPath == null) { return(null); } if (!outputPath.IsRelative) { throw new ArgumentException("The feed output path must be relative"); } // Generate the feed and document MemoryStream stream = new MemoryStream(); FeedSerializer.SerializeXml(feedType, feed, stream); stream.Position = 0; return(context.GetDocument(stream, new MetadataItems { new MetadataItem(Keys.RelativeFilePath, outputPath), new MetadataItem(Keys.WritePath, outputPath) })); }
/// <inheritdoc /> public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { return(_contextPatterns != null ? Execute(null, _contextPatterns.Invoke <string[]>(context, "while getting patterns"), context) : inputs.AsParallel().SelectMany(context, input => Execute(input, _documentPatterns.Invoke <string[]>(input, context, "while getting patterns"), context))); }
// Call this each time you need the value, passing in a postProcessing function if required // If no document delegate is specified, then this will get and cache the value on first request public T GetValue(IDocument document, IExecutionContext context, Func <T, T> postProcessing = null) { if (_documentConfig == null) { if (_gotValue) { return(_value); } _value = _contextConfig == null ? _defaultValue : _contextConfig.Invoke <T>(context); if (postProcessing != null) { _value = postProcessing(_value); } _gotValue = true; return(_value); } T value = _documentConfig.Invoke <T>(document, context); if (postProcessing != null) { value = postProcessing(value); } return(value); }
IEnumerable <IDocument> IModule.Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { if (_executeDocuments != null) { return(inputs.SelectMany(x => _executeDocuments.Invoke <IEnumerable <IDocument> >(x, context) ?? Array.Empty <IDocument>())); } else { return(_executeContext.Invoke <IEnumerable <IDocument> >(context) ?? Array.Empty <IDocument>()); } }
private static string GetGlobbingPattern(IExecutionContext context, ContextConfig pagesPattern, ContextConfig ignorePaths, string extension) { List <string> segments = new List <string>(); IEnumerable <string> ignorePatterns = ignorePaths?.Invoke <IEnumerable <string> >(context).Select(x => "!" + x); if (ignorePatterns != null) { segments.AddRange(ignorePatterns); } segments.Add($"{(pagesPattern == null ? string.Empty : pagesPattern.Invoke(context) + "/")}**/{{!.git,}}/**/{{!_,}}*.{extension}"); return(segments.Count == 1 ? segments[0] : $"{{{string.Join(",", segments)}}}"); }
/// <inheritdoc /> public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { // Get the feed Feed feed = new Feed { ID = _feedId?.Invoke <Uri>(context, "while reading feed ID from settings"), Title = _feedTitle?.Invoke <string>(context, "while reading feed title from settings"), Description = _feedDescription?.Invoke <string>(context, "while reading feed description from settings"), Author = _feedAuthor?.Invoke <string>(context, "while reading feed author from settings"), Published = _feedPublished?.Invoke <DateTime?>(context, "while reading feed published date from settings"), Updated = _feedUpdated?.Invoke <DateTime?>(context, "while reading feed updated date from settings"), Link = _feedLink?.Invoke <Uri>(context, "while reading feed link from settings"), ImageLink = _feedImageLink?.Invoke <Uri>(context, "while reading feed image from settings"), Copyright = _feedCopyright?.Invoke <string>(context, "while reading feed copyright from settings") }; // Add items context.ForEach(inputs.Take(_maximumItems), input => { feed.Items.Add(new FeedItem { ID = _itemId?.Invoke <Uri>(input, context, "while reading ID for feed"), Title = _itemTitle?.Invoke <string>(input, context, "while reading title for feed"), Description = _itemDescription?.Invoke <string>(input, context, "while reading description for feed"), Author = _itemAuthor?.Invoke <string>(input, context, "while reading author for feed"), Published = _itemPublished?.Invoke <DateTime?>(input, context, "while reading published date for feed"), Updated = _itemUpdated?.Invoke <DateTime?>(input, context, "while reading updated date for feed"), Link = _itemLink?.Invoke <Uri>(input, context, "while reading feed link for feed"), ImageLink = _itemImageLink?.Invoke <Uri>(input, context, "while reading image for feed"), Content = _itemContent?.Invoke <string>(input, context, "while reading content for feed"), ThreadLink = _itemThreadLink?.Invoke <Uri>(input, context, "while reading thread link for feed"), ThreadCount = _itemThreadCount?.Invoke <int?>(input, context, "while reading thread count for feed"), ThreadUpdated = _itemThreadUpdated?.Invoke <DateTime?>(input, context, "while reading thread updated for feed") }); }); // Generate the feeds return(new[] { GenerateFeed(FeedType.Rss, feed, _rssPath, context), GenerateFeed(FeedType.Atom, feed, _atomPath, context), GenerateFeed(FeedType.Rdf, feed, _rdfPath, context) }.Where(x => x != null)); }
public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { // Get the feed Feed feed = new Feed { ID = _feedId?.Invoke <Uri>(context), Title = _feedTitle?.Invoke <string>(context), Description = _feedDescription?.Invoke <string>(context), Author = _feedAuthor?.Invoke <string>(context), Published = _feedPublished?.Invoke <DateTime?>(context), Updated = _feedUpdated?.Invoke <DateTime?>(context), Link = _feedLink?.Invoke <Uri>(context), ImageLink = _feedImageLink?.Invoke <Uri>(context), Copyright = _feedCopyright?.Invoke <string>(context) }; // Add items foreach (IDocument input in inputs.Take(_maximumItems)) { feed.Items.Add(new FeedItem { ID = _itemId?.Invoke <Uri>(input, context), Title = _itemTitle?.Invoke <string>(input, context), Description = _itemDescription?.Invoke <string>(input, context), Author = _itemAuthor?.Invoke <string>(input, context), Published = _itemPublished?.Invoke <DateTime?>(input, context), Updated = _itemUpdated?.Invoke <DateTime?>(input, context), Link = _itemLink?.Invoke <Uri>(input, context), ImageLink = _itemImageLink?.Invoke <Uri>(input, context), Content = _itemContent?.Invoke <string>(input, context), ThreadLink = _itemThreadLink?.Invoke <Uri>(input, context), ThreadCount = _itemThreadCount?.Invoke <int?>(input, context), ThreadUpdated = _itemThreadUpdated?.Invoke <DateTime?>(input, context) }); } // Generate the feeds return(new[] { GenerateFeed(FeedType.Rss, feed, _rssPath, context), GenerateFeed(FeedType.Atom, feed, _atomPath, context), GenerateFeed(FeedType.Rdf, feed, _rdfPath, context) }.Where(x => x != null)); }
/// <inheritdoc /> public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { SearchIndexItem[] searchIndexItems = inputs .Select(context, x => _searchIndexItem.TryInvoke <SearchIndexItem>(x, context)) .Where(x => x != null && !string.IsNullOrEmpty(x.Url) && !string.IsNullOrEmpty(x.Title) && !string.IsNullOrEmpty(x.Content)) .ToArray(); if (searchIndexItems.Length == 0) { Trace.Warning("It's not possible to build the search index because no documents contain the necessary metadata."); return(Array.Empty <IDocument>()); } string[] stopwords = GetStopwords(context); StringBuilder scriptBuilder = BuildScript(searchIndexItems, stopwords, context); string script = _script(scriptBuilder, context); // Get the output path MetadataItems metadata = null; FilePath outputPath = _path?.Invoke <FilePath>(context, "while getting output path"); if (outputPath != null) { if (!outputPath.IsRelative) { throw new ArgumentException("The output path must be relative"); } metadata = new MetadataItems { { Keys.RelativeFilePath, outputPath }, { Keys.WritePath, outputPath } }; } return(new [] { context.GetDocument(script, metadata) }); }
public virtual IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { IEnumerable <IDocument> documents; if (_documentDocuments != null) { documents = inputs.SelectMany(context, x => _documentDocuments.Invoke <IEnumerable <IDocument> >(x, context)); } else if (_contextDocuments != null) { documents = _contextDocuments.Invoke <IEnumerable <IDocument> >(context, "while getting documents"); } else { documents = string.IsNullOrEmpty(_pipeline) ? context.Documents.ExceptPipeline(context.Pipeline.Name) : context.Documents.FromPipeline(_pipeline); } if (_predicate != null) { documents = documents.Where(context, x => _predicate(x, context)); } return(documents); }
public void Add(string name, ContextConfig contextConfig) => Add(name, (args, content, doc, ctx) => { string result = contextConfig?.Invoke <string>(ctx); return(result != null ? ctx.GetShortcodeResult(ctx.GetContentStream(result)) : null); });