protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            writer.AddAttribute("rel", targetIsAmp ? "amphtml" :"canonical");
            var  ampPageHasDefaults  = ampPageRoute.DefaultValues.Any();
            var  fullPageHasDefaults = fullPageRoute.DefaultValues.Any();
            bool isDefault;

            if (!fullPageHasDefaults)
            {
                isDefault = !context.Parameters.Any();
            }
            else
            {
                var urlWithDefault = ampPageRoute.BuildUrl(ampPageRoute.DefaultValues);
                var urlWithCurrent = ampPageRoute.BuildUrl(context.Parameters);
                isDefault = urlWithDefault == urlWithCurrent;
            }
            string pageUrl;

            if (targetIsAmp)
            {
                pageUrl = isDefault ?
                          ampPageRoute.BuildUrl(ampPageRoute.DefaultValues) :
                          ampPageRoute.BuildUrl(context.Parameters);
            }
            else
            {
                pageUrl = isDefault ?
                          fullPageRoute.BuildUrl(fullPageRoute.DefaultValues) :
                          fullPageRoute.BuildUrl(context.Parameters);
            }

            writer.AddAttribute("href", context.HttpContext.ToAbsolutePath(pageUrl).AbsoluteUri);
            base.AddAttributesToRender(writer, context);
        }
Exemple #2
0
 public string GetResourceUrl(ILocalResourceLocation resource,
                              IDotvvmRequestContext context,
                              string name)
 {
     return(resourceRoute.BuildUrl(new Dictionary <string, object?> {
         [HashParameterName] = GetVersionHash(resource, context, name),
         [NameParameterName] = EncodeResourceName(name)
     }));
 }
 public string GetResourceUrl(ILocalResourceLocation resource, IDotvvmRequestContext context, string name) =>
 resourceRoute.BuildUrl(new Dictionary <string, object>
 {
     ["hash"] = GetVersionHash(resource, context, name),
     ["name"] = EncodeResourceName(name)
 });