public HeadRestConfigComponent(HeadRest headRest) => _headRest = headRest;
protected override void ApplicationStarted(UmbracoApplicationBase app, ApplicationContext ctx) { // Configure mapping Mapper.AddProfile <ViewModelMappingProfile>(); // Configure endpoint HeadRest.ConfigureEndpoint(new HeadRestOptions { CustomRouteMappings = new HeadRestRouteMap() .For("^/(?<altRoute>init|routes)/?$").MapTo("/") .For("^/(blog)/(?<page>[0-9]+)/?$").MapTo("/$1/"), ViewModelMappings = new HeadRestViewModelMap() .For(HomePage.ModelTypeAlias) .If(x => x.Request.HeadRestRouteParam("altRoute") == "init") .MapTo <InitViewModel>() .For(HomePage.ModelTypeAlias) .If(x => x.Request.HeadRestRouteParam("altRoute") == "routes") .MapTo <RoutesViewModel>() .For(HomePage.ModelTypeAlias).MapTo <HomePageViewModel>() .For(StandardPage.ModelTypeAlias).MapTo <StandardPageViewModel>() .For(BlogPage.ModelTypeAlias).MapTo <BlogPageViewModel>() .For(BlogPostPage.ModelTypeAlias).MapTo <BlogPostPageViewModel>() }); // Configure auto build CacheRefresherBase <PageCacheRefresher> .CacheUpdated += (sender, args) => { var url = ConfigurationManager.AppSettings["NetlifyWebhookUrl"]; if (!url.IsNullOrWhiteSpace()) { using (var client = new WebClient()) { client.UploadValues(url, "POST", new NameValueCollection()); } } }; // Configure default values ContentService.Created += (sender, args) => { if (args.Entity.ContentType.Alias == BlogPostPage.ModelTypeAlias) { args.Entity.SetValue("publishDate", DateTime.Now); } }; // Configure lucene var indexer = (UmbracoContentIndexer)ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"]; indexer.DocumentWriting += (sender, args) => { if (args.Fields["nodeTypeAlias"].InvariantEquals(BlogPostPage.ModelTypeAlias)) { var publishDate = args.Fields.ContainsKey("publishDate") ? DateTime.Parse(args.Fields["publishDate"]) : DateTime.Parse(args.Fields["createDate"]); var sortableField = new Field("__Sort_publishDate", publishDate.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED); args.Document.Add(sortableField); } }; indexer.GatheringNodeData += (sender, args) => { var publishDate = args.Fields.ContainsKey("publishDate") ? DateTime.Parse(args.Fields["publishDate"]) : DateTime.Parse(args.Fields["createDate"]); args.Fields["searchPublishDate"] = DateTools.DateToString(publishDate, DateTools.Resolution.SECOND); args.Fields.Add("searchPath", string.Join(" ", args.Fields["path"].Split(','))); }; }
public NullOrWhitespaceComponent(HeadRest headRest) => _headRest = headRest;