Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Date and Time Formats in Configuration File #241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 81 additions & 99 deletions Website/Web.config
Original file line number Diff line number Diff line change
@@ -1,180 +1,162 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<configuration>

<appSettings>
<add key="blog:theme" value="OneColumn" />
<add key="blog:name" value="MiniBlog" />
<add key="blog:description" value="I write about web development in ASP.NET and Visual Studio" />
<add key="blog:image" value="https://github.global.ssl.fastly.net/images/modules/logos_page/Octocat.png" />
<add key="blog:postsPerPage" value="5" />
<add key="blog:daysToComment" value="999" />
<add key="blog:moderateComments" value="true" />
<add key="blog:email" value="[email protected]" />
<add key="blog:path" value="" />
<add key="blog:cdnUrl" value="" /> <!-- Converts all image, js and css references to absolute urls. Example: value="http://static.mydomain.com" -->
<add key="PreserveLoginUrl" value="true" />
<add key="webpages:Enabled" value="true" />
<add key="webpages:Version" value="3.0.0.0" />
<add key="blog:theme" value="OneColumn"/>
<add key="blog:name" value="MiniBlog"/>
<add key="blog:description" value="I write about web development in ASP.NET and Visual Studio"/>
<add key="blog:image" value="https://github.global.ssl.fastly.net/images/modules/logos_page/Octocat.png"/>
<add key="blog:postsPerPage" value="5"/>
<add key="blog:daysToComment" value="999"/>
<add key="blog:moderateComments" value="true"/>
<add key="blog:email" value="[email protected]"/>
<add key="blog:path" value=""/>
<add key="blog:cdnUrl" value=""/>
<!-- Converts all image, js and css references to absolute urls. Example: value="http://static.mydomain.com" -->
<add key="PreserveLoginUrl" value="true"/>
<add key="webpages:Enabled" value="true"/>
<add key="webpages:Version" value="3.0.0.0"/>
</appSettings>

<system.web>
<compilation debug="false" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" enableVersionHeader="false" requestValidationMode="2.0" />
<pages validateRequest="false" />

<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5" enableVersionHeader="false" requestValidationMode="2.0"/>
<pages validateRequest="false"/>
<customErrors mode="RemoteOnly" defaultRedirect="~/">
<error statusCode="404" redirect="~/404/" />
<error statusCode="404" redirect="~/404/"/>
</customErrors>

<authentication mode="Forms">
<forms defaultUrl="~/" loginUrl="~/views/login.cshtml" name="miniblog" timeout="10080">
<credentials passwordFormat="SHA1">
<!-- Password is "demo". Generate your hash password here http://www.sha1-online.com/ -->
<user name="demo" password="89e495e7941cf9e40e6980d14a16bf023ccd4c91" />
<user name="demo" password="89e495e7941cf9e40e6980d14a16bf023ccd4c91"/>
</credentials>
</forms>
</authentication>

<machineKey decryption="AES" validation="SHA1" decryptionKey="435D9CC99471D1E7C70FFEBA5EC71F28048BF9016605B82CC69B091FD317B294" validationKey="25C5D98CE093E77C2F886A6D8C6DA8FBC77CD764A1BF49E5D30CD123C5E19553" />
<machineKey decryption="AES" validation="SHA1" decryptionKey="435D9CC99471D1E7C70FFEBA5EC71F28048BF9016605B82CC69B091FD317B294" validationKey="25C5D98CE093E77C2F886A6D8C6DA8FBC77CD764A1BF49E5D30CD123C5E19553"/>
</system.web>

<system.net>
<mailSettings>
<!-- This example uses Hotmail/Outlook.com. Just modify the username and password -->
<smtp>
<network enableSsl="true" host="smtp.live.com" port="587" userName="[email protected]" password="1234abcd" />
<network enableSsl="true" host="smtp.live.com" port="587" userName="[email protected]" password="1234abcd"/>
</smtp>
</mailSettings>
</system.net>

<system.webServer>
<urlCompression doDynamicCompression="true" doStaticCompression="true" />

<modules runAllManagedModulesForAllRequests="false">
<!-- Remove this to disable HTML minification-->
<add name="WhitespaceModule" type="WhitespaceModule" preCondition="managedHandler" />
</modules>

<urlCompression doDynamicCompression="true" doStaticCompression="true"/>
<modules runAllManagedModulesForAllRequests="false">
<!-- Remove this to disable HTML minification-->
<add name="WhitespaceModule" type="WhitespaceModule" preCondition="managedHandler"/>
</modules>
<handlers>
<remove name="CommentHandler" />
<add name="CommentHandler" verb="*" type="CommentHandler" path="/comment.ashx" />
<remove name="PostHandler" />
<add name="PostHandler" verb="POST" type="PostHandler" path="/post.ashx" />
<remove name="MetaWebLogHandler" />
<add name="MetaWebLogHandler" verb="POST,GET" type="MetaWeblogHandler" path="/metaweblog" />
<remove name="FeedHandler" />
<add name="FeedHandler" verb="GET" type="FeedHandler" path="/feed/*" />
<remove name="CssHandler" />
<add name="CssHandler" verb="GET" type="MinifyHandler" path="*.css" />
<remove name="JsHandler" />
<add name="JsHandler" verb="GET" type="MinifyHandler" path="*.js" />
<remove name="CommentHandler"/>
<add name="CommentHandler" verb="*" type="CommentHandler" path="/comment.ashx"/>
<remove name="PostHandler"/>
<add name="PostHandler" verb="POST" type="PostHandler" path="/post.ashx"/>
<remove name="MetaWebLogHandler"/>
<add name="MetaWebLogHandler" verb="POST,GET" type="MetaWeblogHandler" path="/metaweblog"/>
<remove name="FeedHandler"/>
<add name="FeedHandler" verb="GET" type="FeedHandler" path="/feed/*"/>
<remove name="CssHandler"/>
<add name="CssHandler" verb="GET" type="MinifyHandler" path="*.css"/>
<remove name="JsHandler"/>
<add name="JsHandler" verb="GET" type="MinifyHandler" path="*.js"/>
</handlers>

<httpErrors>
<remove statusCode="404" />
<error statusCode="404" responseMode="ExecuteURL" path="/404.cshtml" />
<remove statusCode="404"/>
<error statusCode="404" responseMode="ExecuteURL" path="/404.cshtml"/>
</httpErrors>

<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />

<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00"/>
<remove fileExtension=".woff"/>
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff"/>
</staticContent>

<security>
<requestFiltering allowDoubleEscaping="true">
<fileExtensions>
<remove fileExtension=".cshtml" />
<add fileExtension=".cshtml" allowed="true" />
<remove fileExtension=".cshtml"/>
<add fileExtension=".cshtml" allowed="true"/>
</fileExtensions>
</requestFiltering>
</security>

<httpProtocol>
<customHeaders>
<remove name="x-powered-by" />
<add name="Content-Security-Policy" value="object-src 'none';" />
<add name="Arr-Disable-Session-Affinity" value="True" />
<remove name="x-powered-by"/>
<add name="Content-Security-Policy" value="object-src 'none';"/>
<add name="Arr-Disable-Session-Affinity" value="True"/>
</customHeaders>
</httpProtocol>

<defaultDocument>
<files>
<remove value="index.cshtml" />
<add value="index.cshtml" />
<remove value="index.cshtml"/>
<add value="index.cshtml"/>
</files>
</defaultDocument>

<rewrite>
<rules>
<clear />
<clear/>
<rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<match url="*"/>
<conditions>
<add input="{CACHE_URL}" pattern="*://www.*" />
<add input="{CACHE_URL}" pattern="*://www.*"/>
</conditions>
<action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" />
<action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent"/>
</rule>
<rule name="ProtectStorageXml" stopProcessing="true">
<match url="posts/(.*)\.xml" />
<action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
<match url="posts/(.*)\.xml"/>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden"/>
</rule>
<rule name="BlogEngine slug" stopProcessing="true">
<match url="^post/(.*)\.aspx" ignoreCase="true" />
<action type="Redirect" redirectType="Permanent" url="/post/{R:1}" />
<match url="^post/(.*)\.aspx" ignoreCase="true"/>
<action type="Redirect" redirectType="Permanent" url="/post/{R:1}"/>
</rule>
<rule name="slug" stopProcessing="true">
<match url="^post/(.*)" ignoreCase="true" />
<action type="Rewrite" url="?slug={R:1}" />
<match url="^post/(.*)" ignoreCase="true"/>
<action type="Rewrite" url="?slug={R:1}"/>
</rule>
<rule name="paging" stopProcessing="true">
<match url="^(page/)([\d]{0,})" ignoreCase="true" />
<action type="Rewrite" url="?page={R:2}" />
<match url="^(page/)([\d]{0,})" ignoreCase="true"/>
<action type="Rewrite" url="?page={R:2}"/>
</rule>
<rule name="category" stopProcessing="true">
<match url="^category/([^/]+)(/page/)?([\d]+)?" ignoreCase="true" />
<action type="Rewrite" url="?category={UrlEncode:{R:1}}&amp;page={R:3}" />
<match url="^category/([^/]+)(/page/)?([\d]+)?" ignoreCase="true"/>
<action type="Rewrite" url="?category={UrlEncode:{R:1}}&amp;page={R:3}"/>
</rule>
<rule name="robots.txt" stopProcessing="true">
<match url="robots.txt" />
<action type="Rewrite" url="views/robots/robots.cshtml" />
<match url="robots.txt"/>
<action type="Rewrite" url="views/robots/robots.cshtml"/>
</rule>
<rule name="sitemap" stopProcessing="true">
<match url="sitemap.xml" />
<action type="Rewrite" url="views/robots/sitemap.cshtml" />
<match url="sitemap.xml"/>
<action type="Rewrite" url="views/robots/sitemap.cshtml"/>
</rule>
<rule name="fingerprint" stopProcessing="true">
<match url="(.+)(_([0-9]{18})+\.)([\S]+)" />
<action type="Rewrite" url="{R:1}.{R:4}" />
<match url="(.+)(_([0-9]{18})+\.)([\S]+)"/>
<action type="Rewrite" url="{R:1}.{R:4}"/>
</rule>
</rules>

<outboundRules>
<clear />
<clear/>
<rule name="Remove ETag">
<match serverVariable="RESPONSE_ETag" pattern=".+" />
<action type="Rewrite" value="" />
<match serverVariable="RESPONSE_ETag" pattern=".+"/>
<action type="Rewrite" value=""/>
</rule>

<rule name="Send correct Vary">
<match serverVariable="RESPONSE_Vary" pattern=".+" />
<action type="Rewrite" value="Accept-Encoding, If-Modified-Since" />
<match serverVariable="RESPONSE_Vary" pattern=".+"/>
<action type="Rewrite" value="Accept-Encoding, If-Modified-Since"/>
</rule>
</outboundRules>
</rewrite>
</system.webServer>

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</configuration>
15 changes: 15 additions & 0 deletions Website/app_code/code/Blog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ static Blog()
Image = ConfigurationManager.AppSettings.Get("blog:image");
ModerateComments = bool.Parse(ConfigurationManager.AppSettings.Get("blog:moderateComments"));
BlogPath = ConfigurationManager.AppSettings.Get("blog:path");

DateFormat = GetStringAppSetting("blog:dateFormat", "MMMM d. yyyy");
DateTimeFormat = GetStringAppSetting("blog:dateTimeFormat", "MMMM d. yyyy HH:mm");
DateTimeFormatTitle = GetStringAppSetting("blog:dateTimeFormatTitle", "yyyy-MM-ddTHH:mm");
}

public static string Title { get; private set; }
Expand All @@ -31,7 +35,18 @@ static Blog()
public static int DaysToComment { get; private set; }
public static bool ModerateComments { get; private set; }
public static string BlogPath { get; private set; }
public static string DateFormat { get; private set; }
public static string DateTimeFormat { get; private set; }
public static string DateTimeFormatTitle { get; private set; }

private static string GetStringAppSetting(string setting, string defaultValue){

var value = ConfigurationManager.AppSettings.Get(setting);
value = value == null ? defaultValue : value;

return value;
}

public static string CurrentSlug
{
get { return (HttpContext.Current.Request.QueryString["slug"] ?? string.Empty).Trim().ToLowerInvariant(); }
Expand Down
4 changes: 2 additions & 2 deletions Website/themes/OffCanvas/Comment.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

@helper Date()
{
var title = Model.PubDate.ToString("yyyy-MM-ddTHH:mm");
var display = Model.PubDate.ToString("MMMM d. yyyy HH:mm");
var title = Model.PubDate.ToString(Blog.DateTimeFormatTitle);
var display = Model.PubDate.ToString(Blog.DateTimeFormat);
<time datetime="@title" itemprop="commentTime">@display</time>
}
@helper Author()
Expand Down
2 changes: 1 addition & 1 deletion Website/themes/OffCanvas/Post.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else
<a href="@Model.Url" itemprop="url">@Model.Title</a>
</h1>
<div>
<abbr title="@Model.PubDate.ToLocalTime()" itemprop="datePublished">@Model.PubDate.ToLocalTime().ToString("MMMM d. yyyy")</abbr>
<abbr title="@Model.PubDate.ToLocalTime()" itemprop="datePublished">@Model.PubDate.ToLocalTime().ToString(Blog.DateFormat)</abbr>
<a href="@Model.Url#comments">
<em class="glyphicon glyphicon-comment"></em>
@Model.CountApprovedComments(Context) Comments
Expand Down
4 changes: 2 additions & 2 deletions Website/themes/OneColumn/Comment.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

@helper Date()
{
var title = Model.PubDate.ToString("yyyy-MM-ddTHH:mm");
var display = Model.PubDate.ToString("MMMM d. yyyy HH:mm");
var title = Model.PubDate.ToString(Blog.DateTimeFormatTitle);
var display = Model.PubDate.ToString(Blog.DateTimeFormat);
<time datetime="@title" itemprop="commentTime">@display</time>
}
@helper Author()
Expand Down
2 changes: 1 addition & 1 deletion Website/themes/OneColumn/Post.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a href="@Model.Url" itemprop="url">@Model.Title</a>
</h1>
<div>
<abbr title="@Model.PubDate.ToLocalTime()" itemprop="datePublished">@Model.PubDate.ToLocalTime().ToString("MMMM d. yyyy")</abbr>
<abbr title="@Model.PubDate.ToLocalTime()" itemprop="datePublished">@Model.PubDate.ToLocalTime().ToString(Blog.DateFormat)</abbr>
<a href="@Model.Url#comments">
<em class="glyphicon glyphicon-comment"></em>
@Model.CountApprovedComments(Context) Comments
Expand Down
4 changes: 2 additions & 2 deletions Website/themes/TwoColumns/Comment.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

@helper Date()
{
var title = Model.PubDate.ToString("yyyy-MM-ddTHH:mm");
var display = Model.PubDate.ToString("MMMM d. yyyy HH:mm");
var title = Model.PubDate.ToString(Blog.DateTimeFormatTitle);
var display = Model.PubDate.ToString(Blog.DateTimeFormat);
<time datetime="@title" itemprop="commentTime">@display</time>
}
@helper Author()
Expand Down
2 changes: 1 addition & 1 deletion Website/themes/TwoColumns/Post.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a href="@Model.Url" itemprop="url">@Model.Title</a>
</h1>
<div>
<abbr title="@Model.PubDate.ToLocalTime()" itemprop="datePublished">@Model.PubDate.ToLocalTime().ToString("MMMM d. yyyy")</abbr>
<abbr title="@Model.PubDate.ToLocalTime()" itemprop="datePublished">@Model.PubDate.ToLocalTime().ToString(Blog.DateFormat)</abbr>
<a href="@Model.Url#comments">
<em class="glyphicon glyphicon-comment"></em>
@Model.CountApprovedComments(Context) Comments
Expand Down