コード例 #1
0
        /// <summary>
        /// Adds a meta robots tag to the head.
        /// </summary>
        public static void AddMetaRobots(this IPageAssetBuilder builder, string name = "robots", string content = "noindex")
        {
            Guard.NotEmpty(name, nameof(name));
            Guard.NotEmpty(content, nameof(content));

            var key = "meta_" + name + '_' + content;

            AddHtmlContent(builder,
                           "head",
                           new HtmlString("<meta name=\"{0}\" content=\"{1}\" />".FormatInvariant(name, content)),
                           key);
        }
コード例 #2
0
 public MenuFilter(
     IMenuStorage menuStorage,
     IMenuService menuService,
     IWidgetProvider widgetProvider,
     IPageAssetBuilder assetBuilder,
     IDisplayHelper displayHelper)
 {
     _menuStorage    = menuStorage;
     _menuService    = menuService;
     _widgetProvider = widgetProvider;
     _assetBuilder   = assetBuilder;
     _displayHelper  = displayHelper;
 }
コード例 #3
0
        /// <summary>
        /// Adds custom html content to a target zone.
        /// </summary>
        /// <param name="targetZone">The zone name to render <paramref name="content"/> in.</param>
        /// <param name="content">The html content to render.</param>
        /// <param name="key">An optional key to ensure uniqueness within the target zone.</param>
        /// <param name="prepend"><c>true</c> renders the <paramref name="content"/> before any zone content.</param>
        public static void AddHtmlContent(this IPageAssetBuilder builder, string targetZone, IHtmlContent content, string key = null, bool prepend = false)
        {
            Guard.NotEmpty(targetZone, nameof(targetZone));
            Guard.NotNull(content, nameof(content));

            if (key.HasValue() && builder.WidgetProvider.ContainsWidget(targetZone, key))
            {
                return;
            }

            builder.WidgetProvider.RegisterWidget(
                targetZone,
                new HtmlWidgetInvoker(content)
            {
                Key = key, Prepend = prepend
            });
        }
コード例 #4
0
        private static void AddCssFilePartsInternal(IPageAssetBuilder builder, bool prepend, params string[] parts)
        {
            const string zoneName = "head_stylesheets";

            if (parts.Length == 0)
            {
                return;
            }

            foreach (var href in parts.Select(x => x.Trim()))
            {
                AddHtmlContent(builder,
                               zoneName,
                               new HtmlString("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />".FormatInvariant(builder.TryFindMinFile(href))),
                               href,
                               prepend);
            }
        }
コード例 #5
0
        private static void AddScriptPartsInternal(IPageAssetBuilder builder, AssetLocation location, bool prepend, params string[] parts)
        {
            if (parts.Length == 0)
            {
                return;
            }

            string zoneName = location == AssetLocation.Head ? "head_scripts" : "scripts";

            foreach (var src in parts.Select(x => x.Trim()))
            {
                AddHtmlContent(builder,
                               zoneName,
                               new HtmlString("<script src=\"{0}\"></script>".FormatInvariant(builder.TryFindMinFile(src))),
                               src,
                               prepend);
            }
        }
コード例 #6
0
        private static void AddCanonicalUrlPartsInternal(IPageAssetBuilder builder, bool prepend, params string[] parts)
        {
            const string zoneName = "head_canonical";

            if (parts.Length == 0)
            {
                return;
            }

            foreach (var href in parts.Select(x => x.Trim()))
            {
                AddHtmlContent(builder,
                               zoneName,
                               new HtmlString("<link rel=\"canonical\" href=\"{0}\" />".FormatInvariant(href)),
                               href,
                               prepend);
            }
        }
コード例 #7
0
 /// <summary>
 /// Prepends CSS file parts to the currently rendered page (rendered in zone <c>head_stylesheets</c>).
 /// </summary>
 /// <param name="parts">The parts to prepend.</param>
 public static void PrependCssFileParts(this IPageAssetBuilder builder, params string[] parts) => AddCssFilePartsInternal(builder, true, parts);
コード例 #8
0
 /// <summary>
 /// Prepends head script file parts to the currently rendered page (rendered in zone <c>head_scripts</c>).
 /// </summary>
 /// <param name="parts">The parts to prepend.</param>
 public static void PrependHeadScriptParts(this IPageAssetBuilder builder, params string[] parts) => AddScriptPartsInternal(builder, AssetLocation.Head, true, parts);
コード例 #9
0
 /// <summary>
 /// Appends foot script file parts to the currently rendered page (rendered in zone <c>scripts</c>).
 /// </summary>
 /// <param name="parts">The parts to append.</param>
 public static void AppendScriptParts(this IPageAssetBuilder builder, params string[] parts) => AddScriptPartsInternal(builder, AssetLocation.Foot, false, parts);
コード例 #10
0
 /// <summary>
 /// Appends canonical url parts to the currently rendered page (rendered in zone <c>head_canonical</c>).
 /// </summary>
 /// <param name="parts">The parts to append.</param>
 public static void AppendCanonicalUrlParts(this IPageAssetBuilder builder, params string[] parts) => AddCanonicalUrlPartsInternal(builder, false, parts);
コード例 #11
0
 /// <summary>
 /// Prepends meta keyword parts to the currently rendered page.
 /// </summary>
 /// <param name="parts">The parts to prepend.</param>
 public static void PrependMetaKeywordsParts(this IPageAssetBuilder builder, params string[] parts) => builder.AddMetaKeywordParts(parts, true);
コード例 #12
0
 /// <summary>
 /// Prepends meta description parts to the currently rendered page.
 /// </summary>
 /// <param name="parts">The parts to prepend.</param>
 public static void PrependMetaDescriptionParts(this IPageAssetBuilder builder, params string[] parts) => builder.AddMetaDescriptionParts(parts, true);
コード例 #13
0
 /// <summary>
 /// Prepends document title parts to the currently rendered page.
 /// </summary>
 /// <param name="parts">The parts to prepend.</param>
 public static void PrependTitleParts(this IPageAssetBuilder builder, params string[] parts) => builder.AddTitleParts(parts, true);
コード例 #14
0
 public PageAssetsTagHelper(IPageAssetBuilder assetBuilder, SeoSettings seoSettings)
 {
     _assetBuilder = assetBuilder;
     _seoSettings  = seoSettings;
 }