public void Ping(string sitemapUrl) { Log.Info("Ping search engines with sitemapUrl='{0}'.", sitemapUrl); //need some DI here List <ISitemapPing> providers = new List <SearchEngines.ISitemapPing>() { new GoogleSitemapPing(Log), new BingSitemapPing(Log) }; //loop through providers and invoke their sitemap ping API foreach (var isitemapping in providers) { Log.Info("Invoking '{0}' and calling Ping.", isitemapping.GetType().Name); isitemapping.Ping(sitemapUrl); } }
public string ComponentOutput(Asset asset, OutputContext context) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version='1.0' encoding='UTF-8'?>"); sb.AppendLine(string.Format("<!-- generated {0} -->", DateTime.UtcNow.ToString("O"))); sb.AppendLine(@"<sitemapindex xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd' xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>" ); bool forceHttps = asset.Raw["sitemap_force_https"] == "true"; foreach (var panel in asset.GetPanels("sitemap_roots")) { var sitemapAssetsList = new List <Asset>(); if (string.IsNullOrEmpty(panel["sitemap_asset"]) == false) { Asset sitemapAsset = Asset.Load(panel["sitemap_asset"]); sitemapAssetsList.Add(sitemapAsset); } if (string.IsNullOrEmpty(panel["multi_sitemap_root_path"]) == false && string.IsNullOrEmpty(panel["multi_sitemap_template_id"]) == false) { try { FilterParams fp = new FilterParams(); fp.Add(AssetPropertyNames.TemplateId, Comparison.Equals, int.Parse(panel["multi_sitemap_template_id"])); Asset rootfolder = Asset.Load(panel["multi_sitemap_root_path"]); var foundAssets = rootfolder.GetFilterList(fp); sitemapAssetsList.AddRange(foundAssets); } catch (Exception) { } } Log.Info("sitemapAssetsList count is '{0}'.", sitemapAssetsList.Count); foreach (var sitemapAsset in sitemapAssetsList) { if (sitemapAsset.IsLoaded) { //create dependency to the sitemaproot asset specified asset.AddDependencyTo(sitemapAsset); sb.AppendLine("<sitemap>"); string loc = sitemapAsset.GetLink(addDomain: true); if (forceHttps) { loc = loc.Replace("http://", "https://"); } sb.AppendFormat(" <loc>{0}</loc>\n", loc); if (sitemapAsset.PublishDate != null) { //use W3C Datetime format, yyyy-MM-dd sb.AppendFormat(" <lastmod>{0}</lastmod>\n", sitemapAsset.PublishDate.Value.ToString("yyyy-MM-dd")); } sb.AppendLine("</sitemap>"); } } } sb.AppendLine("</sitemapindex>"); return(sb.ToString()); }
public IEnumerable <CPContrib.SiteMap.SitemapItem> ProcessList(Status notused = null) { DateTime EMPTY_LAST_MOD_DATE = new DateTime(1980, 1, 1); var sitemapList = new List <CPContrib.SiteMap.SitemapItem>(); int count = 0; IEnumerable <Asset> assetList = this._assets ?? new List <Asset>(); Stopwatch sw = new Stopwatch(); sw.Start(); Log.Info("PublishingStatus: {0}", context.PublishingStatus.Name); Log.Info("List.Count: {0}", this._assets.Count); int ignoredCount = 0; foreach (Asset currentAsset in assetList) { bool ignored = this.IgnoreAssetFunc(currentAsset); Log.Debug("asset {0}: ignore func returns {1}", currentAsset.Id, ignored); if (ignored) { ignoredCount++; } if (currentAsset.IsLoaded == false) { Log.Warn("asset {0}: isloaded={1}", currentAsset.Id, currentAsset.IsLoaded); } if (ignored == false && currentAsset.IsLoaded) { var url = new CPContrib.SiteMap.SitemapItem(); url.Asset = currentAsset; Log.Debug("asset {0}: begin processing", currentAsset.Id); // Is this really needed? Seems to add un-needed overhead. Saving too much data to Content fields. //string link = sitemapLinkCache.GetOrUpdateCachedLink(currentAsset); var lastPubUrls = currentAsset.GetLastPublishedLinks(true, ProtocolType.Https); string link = lastPubUrls.FirstOrDefault(); //TEMP HACK if (link != null && link.StartsWith("httpss://")) { Log.Debug("currentAsset.Id={0} GetPublishedLinks has httpss", currentAsset.Id); link = link.Replace("httpss://", "https://"); } if (string.IsNullOrEmpty(link)) { link = currentAsset.GetLink(addDomain: true, protocolType: ProtocolType.Https); } Log.Debug("asset {0}: link is '{1}'", currentAsset.Id, link); if (!string.IsNullOrEmpty(link)) { url.Loc = link; url.LastMod = (url.Asset.ModifiedDate == null ? EMPTY_LAST_MOD_DATE : url.Asset.ModifiedDate.Value); string assetpathStr = url.Asset.AssetPath.ToString(); var defaultEntry = GetDefaultEntry(assetpathStr); var overrideEntry = GetOverrideEntry(assetpathStr); //call function assigned to AssignPropertiesFunc this.AssignMetaFunc(url, defaultEntry, overrideEntry); if (url.changefreq == SitemapConstants.Tiered_LastMod) { this.Tiered_LastMod_ChangeFreq(url); } //add to list to output Log.Debug("asset {0}: added to list", currentAsset.Id); sitemapList.Add(url); } } } //sitemapLinkCache.SaveLinkCache(); sw.Stop(); Log.Info("processed {0} assets.", assetList.Count()); Log.Info("ignored {0} assets.", ignoredCount); Log.Info("sitemap list contains {0} assets", sitemapList.Count); Log.Info("ProcessList took {0} seconds", sw.Elapsed.TotalSeconds); return(sitemapList); }