/// <summary>加载时触发</summary> protected override void OnLoaded() { #if __CORE__ if (StartPage.IsNullOrEmpty()) { StartPage = // 避免出现生成 "/Admin/Admin/Index/Main" 这样的情况 //NewLife.Web.HttpContext.Current?.Request.PathBase.ToString().EnsureEnd("/") + "/Admin/Index/Main"; } #else if (StartPage.IsNullOrEmpty()) { StartPage = System.Web.HttpRuntime.AppDomainAppVirtualPath.EnsureEnd("/") + "Admin/Index/Main"; } #endif var web = Runtime.IsWeb; //if (AvatarPath.IsNullOrEmpty()) AvatarPath = web ? "..\\Avatars" : "Avatars"; if (DefaultRole.IsNullOrEmpty() || DefaultRole == "3") { DefaultRole = "普通用户"; } if (JwtSecret.IsNullOrEmpty() || JwtSecret.Split(':').Length != 2) { JwtSecret = $"HS256:{Rand.NextString(16)}"; } // 取版权信息 if (Copyright.IsNullOrEmpty()) { var asm = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly(); if (asm != null) { var att = asm.GetCustomAttribute <AssemblyCopyrightAttribute>(); if (att != null) { Copyright = att.Copyright; } } } base.OnLoaded(); }
public XElement ToXElement() { var headElems = new[] { new XElement("link", new XAttribute("rel", "canonical"), new XAttribute("href", URL)), new XElement("meta", new XAttribute("charset", "utf-8")), Style.IsNullOrEmpty() ? null : new XElement("meta", new XAttribute("property", "fb:article_style"), new XAttribute("content", Style)), new XElement("meta", new XAttribute("property", "fb:use_automatic_ad_placement"), new XAttribute("content", AutoAdPlacement)), Version.IsNullOrEmpty() ? null : new XElement("meta", new XAttribute("property", "op:version"), new XAttribute("content", Version)), NewsFeedTitle.IsNullOrEmpty() ? null : new XElement("meta", new XAttribute("property", "og:title"), new XAttribute("content", NewsFeedTitle)), NewsFeedDescription.IsNullOrEmpty() ? null : new XElement("meta", new XAttribute("property", "og:description"), new XAttribute("content", NewsFeedDescription)), NewsFeedImage.IsNullOrEmpty() ? null : new XElement("meta", new XAttribute("property", "og:image"), new XAttribute("content", NewsFeedImage)), new XElement("title", Title), }; var headerMedia = Items.FirstOrDefault(i => i.IsHeader && i.Type == InstantArticleItemType.Video || i.Type == InstantArticleItemType.Image); var headerMediaElem = headerMedia == null ? null : InstantArticleModelFactory.CreateFrom((int)headerMedia.ItemTypeId, headerMedia).ToXElement(); var headerAds = Items.Where(i => i.IsHeader && i.Type == InstantArticleItemType.Ad) .Select(i => InstantArticleModelFactory.CreateFrom((int)i.ItemTypeId, i)) .ToArray(); var headerAdElem = headerAds.IsNullOrEmpty() ? null : headerAds.Length == 1 ? headerAds.First().ToXElement() : new XElement("section", new XAttribute("class", "op-ad-template"), headerAds.Select(a => a.ToXElement())); var headerElems = new object[] { headerAdElem, headerMediaElem, new XElement("h1", Title), new XElement("h2", SubTitle), new XElement("h3", new XAttribute("class", "op-kicker"), Kicker), Authors.IsNullOrEmpty() ? null : Authors.Select(a => new XElement("address", a)).ToArray(), !DatePublished.HasValue ? null : new XElement("time", new XAttribute("property", "op-published"), new XAttribute("datettime", DatePublished)), !DateModified.HasValue ? null : new XElement("time", new XAttribute("property", "op-modified"), new XAttribute("datettime", DateModified)), }; var bodyElems = Items.Where(i => !i.IsHeader && !i.IsCaption) .Select(i => InstantArticleModelFactory.CreateFrom((int)i.ItemTypeId, i)) .Select(i => i.ToXElement()).ToArray(); var footerElems = new object[] { Credits.IsNullOrEmpty() ? null : new XElement("aside", Credits), Copyright.IsNullOrEmpty() ? null : new XElement("small", Copyright) }; return(new XElement("html", new XElement("head", headElems), new XElement("body", new XElement("article", new XElement("header", headerElems), bodyElems, new XElement("footer", footerElems) )))); }