diff --git a/Teknik/Areas/Blog/BlogAreaRegistration.cs b/Teknik/Areas/Blog/BlogAreaRegistration.cs index 32d3bc6..46a3ded 100644 --- a/Teknik/Areas/Blog/BlogAreaRegistration.cs +++ b/Teknik/Areas/Blog/BlogAreaRegistration.cs @@ -2,6 +2,7 @@ using System.Web.Mvc; using System.Web.Optimization; using Teknik.Configuration; +using Teknik.Helpers; namespace Teknik.Areas.Blog { @@ -60,12 +61,12 @@ namespace Teknik.Areas.Blog ); // Register Script Bundles - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/blog").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/blog", config.CdnHost).Include( "~/Scripts/bootbox/bootbox.min.js", "~/Scripts/MarkdownDeepLib.min.js", "~/Areas/Blog/Scripts/Blog.js")); // Register Style Bundles - BundleTable.Bundles.Add(new StyleBundle("~/Content/blog").Include( + BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/blog", config.CdnHost).Include( "~/Content/mdd_styles.css", "~/Areas/Blog/Content/Blog.css")); } diff --git a/Teknik/Areas/Contact/ContactAreaRegistration.cs b/Teknik/Areas/Contact/ContactAreaRegistration.cs index e6d6c16..02939eb 100644 --- a/Teknik/Areas/Contact/ContactAreaRegistration.cs +++ b/Teknik/Areas/Contact/ContactAreaRegistration.cs @@ -2,6 +2,7 @@ using System.Web.Mvc; using System.Web.Optimization; using Teknik.Configuration; +using Teknik.Helpers; namespace Teknik.Areas.Contact { @@ -36,7 +37,7 @@ namespace Teknik.Areas.Contact ); // Register Bundles - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/contact").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/contact", config.CdnHost).Include( "~/Areas/Contact/Scripts/Contact.js")); } } diff --git a/Teknik/Areas/Help/HelpAreaRegistration.cs b/Teknik/Areas/Help/HelpAreaRegistration.cs index 21a6070..c162e5e 100644 --- a/Teknik/Areas/Help/HelpAreaRegistration.cs +++ b/Teknik/Areas/Help/HelpAreaRegistration.cs @@ -2,6 +2,7 @@ using System.Web.Mvc; using System.Web.Optimization; using Teknik.Configuration; +using Teknik.Helpers; namespace Teknik.Areas.Help { @@ -108,7 +109,7 @@ namespace Teknik.Areas.Help ); // Register Style Bundles - BundleTable.Bundles.Add(new StyleBundle("~/Content/help").Include( + BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/help", config.CdnHost).Include( "~/Areas/Help/Content/Help.css")); } } diff --git a/Teknik/Areas/Home/Views/Home/Index.cshtml b/Teknik/Areas/Home/Views/Home/Index.cshtml index 6aa1a7f..a9b2698 100644 --- a/Teknik/Areas/Home/Views/Home/Index.cshtml +++ b/Teknik/Areas/Home/Views/Home/Index.cshtml @@ -2,6 +2,20 @@ @using Teknik.Areas.Blog.Models @using Teknik.Areas.Podcast.Models +@using Teknik.Helpers + +@{ + string logoPath = "/Images/logo-blue.svg"; + + // If we are using a CDN, let's replace it + if (Model.Config.UseCdn) + { + if (!string.IsNullOrEmpty(Model.Config.CdnHost)) + { + logoPath = Model.Config.CdnHost.TrimEnd('/') + logoPath; + } + } +} @Styles.Render("~/Content/home") @Scripts.Render("~/bundles/home") @@ -9,7 +23,7 @@
- Teknik + Teknik

diff --git a/Teknik/Areas/Paste/PasteAreaRegistration.cs b/Teknik/Areas/Paste/PasteAreaRegistration.cs index 0f7eb3e..d085118 100644 --- a/Teknik/Areas/Paste/PasteAreaRegistration.cs +++ b/Teknik/Areas/Paste/PasteAreaRegistration.cs @@ -3,6 +3,7 @@ using System.Web.Mvc; using System.Web.Optimization; using Teknik.Configuration; using Teknik.Controllers; +using Teknik.Helpers; namespace Teknik.Areas.Paste { @@ -77,15 +78,15 @@ namespace Teknik.Areas.Paste ); // Register Script Bundles - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/paste").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/paste", config.CdnHost).Include( "~/Scripts/Highlight/highlight.pack.js", "~/Areas/Paste/Scripts/Paste.js")); - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/syntaxWorker").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/syntaxWorker", config.CdnHost).Include( "~/Areas/Paste/Scripts/SyntaxWorker.js")); - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/highlight").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/highlight", config.CdnHost).Include( "~/Scripts/Highlight/highlight.pack.js")); // Register Style Bundles - BundleTable.Bundles.Add(new StyleBundle("~/Content/paste").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/Content/paste", config.CdnHost).Include( "~/Content/Highlight/github-gist.css", "~/Areas/Paste/Content/Paste.css")); } diff --git a/Teknik/Areas/Podcast/PodcastAreaRegistration.cs b/Teknik/Areas/Podcast/PodcastAreaRegistration.cs index 3bfef22..c556905 100644 --- a/Teknik/Areas/Podcast/PodcastAreaRegistration.cs +++ b/Teknik/Areas/Podcast/PodcastAreaRegistration.cs @@ -2,6 +2,7 @@ using System.Web.Mvc; using System.Web.Optimization; using Teknik.Configuration; +using Teknik.Helpers; namespace Teknik.Areas.Podcast { @@ -52,12 +53,12 @@ namespace Teknik.Areas.Podcast ); // Register Script Bundles - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/podcast").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/podcast", config.CdnHost).Include( "~/Scripts/bootbox/bootbox.min.js", "~/Scripts/jquery.blockUI.js", "~/Areas/Podcast/Scripts/Podcast.js")); // Register Style Bundles - BundleTable.Bundles.Add(new StyleBundle("~/Content/podcast").Include( + BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/podcast", config.CdnHost).Include( "~/Areas/Podcast/Content/Podcast.css")); } } diff --git a/Teknik/Areas/Shortener/ShortenerAreaRegistration.cs b/Teknik/Areas/Shortener/ShortenerAreaRegistration.cs index dcd95c5..4cc1ab7 100644 --- a/Teknik/Areas/Shortener/ShortenerAreaRegistration.cs +++ b/Teknik/Areas/Shortener/ShortenerAreaRegistration.cs @@ -2,6 +2,7 @@ using System.Web.Mvc; using System.Web.Optimization; using Teknik.Configuration; +using Teknik.Helpers; namespace Teknik.Areas.Shortener { @@ -44,7 +45,7 @@ namespace Teknik.Areas.Shortener ); // Register Script Bundles - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/shortener").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/shortener", config.CdnHost).Include( "~/Areas/Shortener/Scripts/Shortener.js")); } } diff --git a/Teknik/Areas/Transparency/TransparencyAreaRegistration.cs b/Teknik/Areas/Transparency/TransparencyAreaRegistration.cs index 9863798..b38ad15 100644 --- a/Teknik/Areas/Transparency/TransparencyAreaRegistration.cs +++ b/Teknik/Areas/Transparency/TransparencyAreaRegistration.cs @@ -2,6 +2,7 @@ using System.Web.Mvc; using System.Web.Optimization; using Teknik.Configuration; +using Teknik.Helpers; namespace Teknik.Areas.Transparency { @@ -28,7 +29,7 @@ namespace Teknik.Areas.Transparency ); // Register Script Bundle - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/transparency").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/transparency", config.CdnHost).Include( "~/Areas/Transparency/Scripts/Transparency.js")); } } diff --git a/Teknik/Areas/User/UserAreaRegistration.cs b/Teknik/Areas/User/UserAreaRegistration.cs index 17082ac..00cc49a 100644 --- a/Teknik/Areas/User/UserAreaRegistration.cs +++ b/Teknik/Areas/User/UserAreaRegistration.cs @@ -2,6 +2,7 @@ using System.Web.Mvc; using System.Web.Optimization; using Teknik.Configuration; +using Teknik.Helpers; namespace Teknik.Areas.Users { @@ -108,18 +109,18 @@ namespace Teknik.Areas.Users ); // Register Script Bundle - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/user").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/user", config.CdnHost).Include( "~/Scripts/bootbox/bootbox.min.js", "~/Scripts/jquery.blockUI.js", "~/Scripts/bootstrap-switch.js", "~/Areas/User/Scripts/User.js")); // Register Script Bundle - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/checkAuthCode").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/checkAuthCode", config.CdnHost).Include( "~/Areas/User/Scripts/CheckAuthCode.js")); // Register Style Bundles - BundleTable.Bundles.Add(new StyleBundle("~/Content/user").Include( + BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/user", config.CdnHost).Include( "~/Content/bootstrap-switch/bootstrap3/bootstrap-switch.css")); } } diff --git a/Teknik/Areas/Vault/VaultAreaRegistration.cs b/Teknik/Areas/Vault/VaultAreaRegistration.cs index 9266db7..533d854 100644 --- a/Teknik/Areas/Vault/VaultAreaRegistration.cs +++ b/Teknik/Areas/Vault/VaultAreaRegistration.cs @@ -2,6 +2,7 @@ using System.Web.Mvc; using System.Web.Optimization; using Teknik.Configuration; +using Teknik.Helpers; namespace Teknik.Areas.Vault { @@ -28,7 +29,7 @@ namespace Teknik.Areas.Vault ); // Register Script Bundle - BundleTable.Bundles.Add(new ScriptBundle("~/bundles/vault").Include( + BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/vault", config.CdnHost).Include( "~/Areas/Vault/Scripts/Vault.js")); } } diff --git a/Teknik/Controllers/DefaultController.cs b/Teknik/Controllers/DefaultController.cs index 2be8f3b..f5699f3 100644 --- a/Teknik/Controllers/DefaultController.cs +++ b/Teknik/Controllers/DefaultController.cs @@ -10,6 +10,7 @@ using Teknik.Configuration; using Piwik.Tracker; using Teknik.Filters; +using Teknik.Helpers; namespace Teknik.Controllers { @@ -51,7 +52,7 @@ namespace Teknik.Controllers public ActionResult Favicon() { // Get favicon - string imageFile = Server.MapPath("~/Images/favicon.ico"); + string imageFile = Server.MapPath(Constants.FAVICON_PATH); return File(imageFile, "image/x-icon"); } @@ -61,7 +62,7 @@ namespace Teknik.Controllers public ActionResult Logo() { // Get favicon - string imageFile = Server.MapPath("~/Images/logo-black.svg"); + string imageFile = Server.MapPath(Constants.LOGO_PATH); return File(imageFile, "image/svg+xml"); } } diff --git a/Teknik/Helpers/Constants.cs b/Teknik/Helpers/Constants.cs index bd97b33..f24426a 100644 --- a/Teknik/Helpers/Constants.cs +++ b/Teknik/Helpers/Constants.cs @@ -11,6 +11,8 @@ namespace Teknik.Helpers public const string SERVERUSER = "Server Admin"; public const string AUTHCOOKIE = "TeknikAuth"; public const string TRUSTEDDEVICECOOKIE = "TeknikTrustedDevice"; + public const string LOGO_PATH = "~/Images/logo-black.svg"; + public const string FAVICON_PATH = "~/Images/favicon.ico"; // Paste Constants public static Dictionary HIGHLIGHTFORMATS = new Dictionary() diff --git a/Teknik/Helpers/UrlExtensions.cs b/Teknik/Helpers/UrlExtensions.cs index 04bfe3d..6b3cf84 100644 --- a/Teknik/Helpers/UrlExtensions.cs +++ b/Teknik/Helpers/UrlExtensions.cs @@ -7,6 +7,7 @@ using System.Web; using System.Web.Mvc; using System.Web.Routing; using System.Web.UI; +using Teknik.Configuration; namespace Teknik { @@ -14,7 +15,17 @@ namespace Teknik { public static string SubRouteUrl(this UrlHelper url, string sub, string routeName) { - return url.SubRouteUrl(sub, routeName, null); + return url.SubRouteUrl(sub, routeName, null, false); + } + + public static string SubRouteUrl(this UrlHelper url, string sub, string routeName, bool useCdn) + { + return url.SubRouteUrl(sub, routeName, null, useCdn); + } + + public static string SubRouteUrl(this UrlHelper url, string sub, string routeName, object routeValues) + { + return url.SubRouteUrl(sub, routeName, routeValues, false); } /// @@ -25,7 +36,7 @@ namespace Teknik /// /// /// - public static string SubRouteUrl(this UrlHelper url, string sub, string routeName, object routeValues) + public static string SubRouteUrl(this UrlHelper url, string sub, string routeName, object routeValues, bool useCdn) { string host = url.RequestContext.HttpContext.Request.Url.Authority; @@ -71,7 +82,22 @@ namespace Teknik } - string absoluteAction = string.Format("{0}://{1}{2}", url.RequestContext.HttpContext.Request.Url.Scheme, domain, rightUrl); + string fullHost = string.Format("{0}://{1}", url.RequestContext.HttpContext.Request.Url.Scheme, domain); + + if (useCdn) + { + // If we are using a CDN, let's replace it + Config config = Config.Load(); + if (config.UseCdn) + { + if (!string.IsNullOrEmpty(config.CdnHost)) + { + fullHost = config.CdnHost.TrimEnd('/'); + } + } + } + + string absoluteAction = string.Format("{0}{1}", fullHost, rightUrl); if (!string.IsNullOrEmpty(subParam)) { @@ -80,6 +106,7 @@ namespace Teknik return absoluteAction; } + public static string GetUrlParameters(this string url) { Uri uri = new Uri(url); diff --git a/Teknik/Views/Shared/_Navbar.cshtml b/Teknik/Views/Shared/_Navbar.cshtml index fab458b..4ce290e 100644 --- a/Teknik/Views/Shared/_Navbar.cshtml +++ b/Teknik/Views/Shared/_Navbar.cshtml @@ -1,6 +1,7 @@ @model Teknik.ViewModels.ViewModelBase @Html.Partial("../../Areas/User/Views/User/_LoginModalPartial", Model) +