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

Resolve web links #21

Open
xperiandri opened this issue Feb 25, 2021 · 0 comments
Open

Resolve web links #21

xperiandri opened this issue Feb 25, 2021 · 0 comments

Comments

@xperiandri
Copy link
Contributor

Getting dependencies from the Web myself looks like implementing it one more time.
Is there a better way?

var fileProvider = environment.ContentRootFileProvider;
var httpClient = new Lazy<HttpClient>();
var options = new WebOptimazerScssOptions
{
    TryImport = (ref string file, string parentPath, out string scss, out string map) =>
    {
        map = String.Empty;

        var uri = new Uri(file, UriKind.RelativeOrAbsolute);
        if (uri.IsAbsoluteUri
        && (uri.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase)
            || uri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)))
        {
            scss = httpClient.Value.GetStringAsync(uri).Result;
            return true;
        }

        var fileName = Path.GetFileName(file);
        var path = Path.GetDirectoryName(file);
        var filePath = $"{path}/_{fileName}.scss";
        var fileInfo = fileProvider.GetFileInfo($"Areas/SecretCircle.BmwTheme/wwwroot/styles/{filePath}");
        if (fileInfo is Microsoft.Extensions.FileProviders.NotFoundFileInfo)
        {
            scss = String.Empty;
            return false;
        }
        else
        {
            using var reader = new StreamReader(fileInfo.CreateReadStream());
            scss = reader.ReadToEnd();
            return true;
        }
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant