Skip to content

Commit

Permalink
include theme-base to make sure sections can display correct
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne committed May 6, 2019
1 parent 5f4d553 commit 2f1377a
Show file tree
Hide file tree
Showing 3 changed files with 906 additions and 47 deletions.
11 changes: 6 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ var cleanCSS = require('gulp-clean-css');
var rename = require('gulp-rename');
var minify = require('gulp-minify');


function handleError(err) {
console.log(err.toString());
this.emit('end');
}
function compileTheme(theme) {
gulp.src('src/ZKEACMS.WebHost/wwwroot/themes/' + theme + '/css/Theme.less')
.pipe(sourcemaps.init())
.pipe(less())
.on("error", handleError)
.pipe(sourcemaps.write())
.pipe(gulp.dest(function (f) {
return f.base;
Expand Down Expand Up @@ -42,10 +46,7 @@ gulp.task('watch:theme-js-css', function (cb) {
noSource: true,
preserveComments: "some"
}))
.on("error", function (error) {
console.log(error.toString())
this.emit('end')
})
.on("error", handleError)
.pipe(gulp.dest(function (f) {
return f.base;
}));
Expand Down
83 changes: 41 additions & 42 deletions src/ZKEACMS.TemplateImporter/Service/TemplateImporterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,7 @@ public ThemeEntity Import(string zipFile)
if (themeName == null) return null;

string extractFilePath = Path.Combine(ThemeBasePath, entry.FullName);
if (entry.FullName.EndsWith(".css"))
{
cssFiles.Add(new PositionEntry
{
Entry = entry.FullName.Substring(themeName.Length + 1)
});
}

if (entry.FullName.EndsWith(".html"))
{
if (entry.FullName.IndexOf('/') != entry.FullName.LastIndexOf('/'))
Expand All @@ -121,41 +115,6 @@ public ThemeEntity Import(string zipFile)

LayoutEntity layout = CreateLayout(themeName);

#region Sort css
foreach (var document in documents)
{
var links = document.DocumentNode.SelectNodes("//link");
if (links == null)
{
continue;
}
for (int i = 0; i < links.Count; i++)
{
string href = links[i].GetAttributeValue("href", string.Empty);

if (href == string.Empty) continue;

if (href.Contains("?"))
{
href = href.Split('?')[0];
}
if (!href.EndsWith(".css")) continue;

foreach (var item in cssFiles)
{
if (item.Entry.EndsWith(href))
{
if (item.Position < i)
{
item.Position = i;
}
break;
}
}
}
}
#endregion

#region Create Page
int index = 1;
foreach (var document in documents)
Expand Down Expand Up @@ -190,6 +149,40 @@ public ThemeEntity Import(string zipFile)
}
_pageService.Add(page);

#region Collect css
var cssLinks = document.DocumentNode.SelectNodes("//link[@rel='stylesheet']");
if (cssLinks != null)
{
for (int i = 0; i < cssLinks.Count; i++)
{
string href = cssLinks[i].GetAttributeValue("href", string.Empty);

if (href == string.Empty) continue;
if (!isOutSidePath(href))
{
href = ConvertToThemePath(themeName, href);
}
if (!cssFiles.Any(m => m.Entry == href))
{
foreach (var item in cssFiles)
{
if (item.Position >= i)
{
item.Position++;
}
}
cssFiles.Add(new PositionEntry
{
Entry = href,
Position = i
});
}

}
}

#endregion

#region Collect Scripts
var scripts = document.DocumentNode.SelectNodes("//script");
StringBuilder pageScripts = new StringBuilder();
Expand Down Expand Up @@ -365,6 +358,7 @@ private ThemeEntity CreateTheme(string themeName, List<PositionEntry> cssFiles)
{
writer.WriteLine("@import url(\"/lib/bootstrap/dist/css/bootstrap.min.css\");");
}
writer.WriteLine("@import url(\"/css/theme-base.css\");");
foreach (var item in cssFiles.OrderBy(m => m.Position))
{
writer.WriteLine("@import url(\"{0}\");", item.Entry);
Expand All @@ -375,6 +369,11 @@ private ThemeEntity CreateTheme(string themeName, List<PositionEntry> cssFiles)
{
using (StreamWriter writer = new StreamWriter(themeFilestram))
{
if (cssFiles.All(css => !BootstrapFilter.IsMatch(css.Entry)))
{
writer.WriteLine("@import url(\"/lib/bootstrap/dist/css/bootstrap.min.css\");");
}
writer.WriteLine("@import url(\"/css/theme-base.css\");");
foreach (var item in cssFiles.OrderBy(m => m.Position))
{
writer.WriteLine("@import url(\"{0}\");", item.Entry);
Expand Down
Loading

0 comments on commit 2f1377a

Please sign in to comment.