This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CypherPotato
committed
Jan 7, 2023
1 parent
71db92b
commit 64778ed
Showing
28 changed files
with
948 additions
and
760 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
Console.WriteLine("Hello, World!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<RootNamespace>compress_images</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
Console.WriteLine("Hello, World!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<RootNamespace>less_compiler</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Sisk.Core.Routing.Handlers; | ||
using System.Collections.Specialized; | ||
|
||
namespace minify | ||
{ | ||
internal class Factory : RequestHandlerFactory | ||
{ | ||
public override IRequestHandler[] BuildRequestHandlers() | ||
{ | ||
return new[] | ||
{ | ||
new MinifyHtmlCssJsRequestHandler() | ||
}; | ||
} | ||
|
||
public override void Setup(NameValueCollection setupParameters) | ||
{ | ||
; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Sisk.Core.Http; | ||
using Sisk.Core.Routing.Handlers; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace minify | ||
{ | ||
public class MinifyHtmlCssJsRequestHandler : IRequestHandler | ||
{ | ||
public string Identifier { get; init; } = Guid.NewGuid().ToString(); | ||
public RequestHandlerExecutionMode ExecutionMode { get; init; } = RequestHandlerExecutionMode.AfterResponse; | ||
|
||
public HttpResponse? Execute(HttpRequest request, HttpContext context) | ||
{ | ||
var rgxOptions = RegexOptions.Compiled | RegexOptions.Multiline; | ||
|
||
if (context.RouterResponse == null) | ||
return null; | ||
if (context.RouterResponse.Content == null) | ||
return null; | ||
|
||
string? mediaType = context.RouterResponse.Headers["Content-Type"] ?? context.RouterResponse.Content.Headers.ContentType?.MediaType; | ||
string content = context.RouterResponse.Content.ReadAsStringAsync().Result; | ||
|
||
if (mediaType == null) | ||
return null; | ||
|
||
else if (mediaType.StartsWith("text/html")) | ||
{ | ||
string minified = content; | ||
|
||
// comments and line start | ||
minified = Regex.Replace(minified, @"<!--(.*?)-->|\s\B", "", rgxOptions); | ||
|
||
// spaced tags | ||
minified = Regex.Replace(minified, @">[\r\n\s]+<", "><", rgxOptions); | ||
|
||
context.RouterResponse.Content = new StringContent(minified); | ||
context.RouterResponse.Headers.Set("Content-Type", mediaType); | ||
context.RouterResponse.Headers.Set("X-Minified-By", "Agirax"); | ||
return context.RouterResponse; | ||
} | ||
else if (mediaType.StartsWith("application/javascript")) | ||
{ | ||
string minified = content; | ||
|
||
// start space | ||
minified = Regex.Replace(minified, @"^\s+", "", rgxOptions); | ||
// single line comments | ||
minified = Regex.Replace(minified, @"^[^\n][\t\s]+//.*\n", "><", rgxOptions); | ||
// multiline line comments | ||
minified = Regex.Replace(minified, @"\/\*[\s\S]*?\*\/", "><", rgxOptions); | ||
|
||
context.RouterResponse.Content = new StringContent(minified); | ||
context.RouterResponse.Headers.Set("Content-Type", mediaType); | ||
context.RouterResponse.Headers.Set("X-Minified-By", "Agirax"); | ||
return context.RouterResponse; | ||
} | ||
else if (mediaType.StartsWith("text/css")) | ||
{ | ||
string minified = content; | ||
|
||
// multiline line comments | ||
minified = Regex.Replace(minified, @"\/\*[\s\S]*?\*\/", "><", rgxOptions); | ||
// trim all spaces | ||
minified = Regex.Replace(minified, @"^\s+|[\r\n\t]+", "", rgxOptions); | ||
|
||
context.RouterResponse.Content = new StringContent(minified); | ||
context.RouterResponse.Headers.Set("Content-Type", mediaType); | ||
context.RouterResponse.Headers.Set("X-Minified-By", "Agirax"); | ||
return context.RouterResponse; | ||
} | ||
else | ||
{ | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\core\src\Sisk.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
Console.WriteLine("Hello, World!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<RootNamespace>resize_images</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.