예제 #1
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.SuppressOutput();
            var bundle = _bundleProvider.GetBundle(BundleName);

            if (bundle != null)
            {
                var files = GetFiles(bundle);
                foreach (var file in files)
                {
                    var src = GetSrc(file);
                    if (src == null)
                    {
                        continue;
                    }

                    if (_options.AppendVersion)
                    {
                        src = GetVersionedSrc(src);
                    }

                    if (bundle.OutputFileUrl.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
                    {
                        output.Content.AppendHtmlLine($"<script src=\"{_htmlEncoder.Encode(src)}\" type=\"text/javascript\"></script>");
                    }
                    else if (bundle.OutputFileUrl.EndsWith(".css", StringComparison.OrdinalIgnoreCase))
                    {
                        output.Content.AppendHtmlLine($"<link href=\"{_htmlEncoder.Encode(src)}\" rel=\"stylesheet\" />");
                    }
                }
            }
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.SuppressOutput();
            var bundle = _bundleProvider.GetBundle(BundleName);

            if (bundle != null)
            {
                var isScript     = bundle.outputFileName.EndsWith(".js", StringComparison.OrdinalIgnoreCase);
                var isStylesheet = bundle.outputFileName.EndsWith(".css", StringComparison.OrdinalIgnoreCase);

                IEnumerable <string> files = GetFiles(bundle);
                foreach (string file in files)
                {
                    var path = file.Replace("wwwroot/", "");

                    if (isScript)
                    {
                        output.Content.AppendHtmlLine($"<script src=\"/{_htmlEncoder.Encode(path)}\" type=\"text/javascript\"></script>");
                    }
                    else if (isStylesheet)
                    {
                        output.Content.AppendHtmlLine($"<link href=\"/{_htmlEncoder.Encode(path)}\" rel=\"stylesheet\" />");
                    }
                }
            }
        }