Skip to content

Commit 872bf0a

Browse files
Move version picker to right of component home link (#159)
* move version picker to right of component home link * add all items to breadcrumbs trail * remove latest text on select and shrink font size * remove assets-manifest and hashing for preview mode * revert changes to breadcrumbs
1 parent ed28d4e commit 872bf0a

File tree

6 files changed

+197
-29
lines changed

6 files changed

+197
-29
lines changed

gulp.d/tasks/build-preview-pages.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const { Transform } = require('stream')
1111
const map = (transform = () => {}, flush = undefined) => new Transform({ objectMode: true, transform, flush })
1212
const vfs = require('vinyl-fs')
1313
const yaml = require('js-yaml')
14-
const { execSync } = require('child_process')
1514

1615
const ASCIIDOC_ATTRIBUTES = { experimental: '', icons: 'font', sectanchors: '', 'source-highlighter': 'highlight.js' }
1716

@@ -100,7 +99,8 @@ function registerPartials (src) {
10099
function registerHelpers (src, previewDest) {
101100
handlebars.registerHelper('resolvePage', resolvePage)
102101
handlebars.registerHelper('resolvePageURL', resolvePageURL)
103-
handlebars.registerHelper('assets-manifest', (assetPath) => assetsManifest(assetPath, previewDest))
102+
// Since we are not creating an assets-manifest.json file in the preview build, we need to mock the helper.
103+
handlebars.registerHelper('assets-manifest', (assetPath) => assetPath)
104104
return vfs.src('helpers/*.js', { base: src, cwd: src }).pipe(
105105
map((file, enc, next) => {
106106
if (!(file.stem === 'assets-manifest')) {
@@ -128,12 +128,6 @@ function compileLayouts (src) {
128128
)
129129
}
130130

131-
function assetsManifest (assetPath, previewDest) {
132-
const manifestPath = execSync(`find ${previewDest} -name assets-manifest.json`).toString().trim()
133-
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'))
134-
return manifest[assetPath]
135-
}
136-
137131
function copyImages (src, dest) {
138132
return vfs
139133
.src('**/*.{png,svg}', { base: src, cwd: src })

gulp.d/tasks/build.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const ospath = require('path')
1111
const path = ospath.posix
1212
const postcss = require('gulp-postcss')
1313
const postcssCalc = require('postcss-calc')
14+
const gulpif = require('gulp-if')
1415
const postcssAdvancedVars = require('postcss-advanced-variables')
1516
const postcssImport = require('postcss-import')
1617
const tailwindcss = require('tailwindcss')
@@ -74,34 +75,34 @@ module.exports = (src, dest, preview) => () => {
7475
.pipe(uglify({ output: { comments: /^! / } }))
7576
// NOTE concat already uses stat from newest combined file
7677
.pipe(concat('js/site.js'))
77-
.pipe(hash({ template: '<%= name %>-<%= hash %><%= ext %>' }))
78+
.pipe(gulpif(!preview, hash({ template: '<%= name %>-<%= hash %><%= ext %>' })))
7879
.pipe(vfs.dest(dest))
79-
.pipe(hash.manifest('assets-manifest.json', { append: true }))
80+
.pipe(gulpif(!preview, hash.manifest('assets-manifest.json', { append: true })))
8081
.pipe(vfs.dest(dest)),
8182
vfs
8283
.src('js/vendor/*([^.])?(.bundle).js', { ...opts, read: false })
8384
.pipe(bundle(opts))
8485
.pipe(uglify({ output: { comments: /^! / } }))
85-
.pipe(hash({ template: '<%= name %>-<%= hash %><%= ext %>' }))
86+
.pipe(gulpif(!preview, hash({ template: '<%= name %>-<%= hash %><%= ext %>' })))
8687
.pipe(vfs.dest(dest))
87-
.pipe(hash.manifest('assets-manifest.json', { append: true }))
88+
.pipe(gulpif(!preview, hash.manifest('assets-manifest.json', { append: true })))
8889
.pipe(vfs.dest(dest)),
8990
vfs
9091
.src('js/vendor/*.min.js', opts)
9192
.pipe(map((file, enc, next) => next(null, Object.assign(file, { extname: '' }, { extname: '.js' }))))
92-
.pipe(hash({ template: '<%= name %>-<%= hash %><%= ext %>' }))
93+
.pipe(gulpif(!preview, hash({ template: '<%= name %>-<%= hash %><%= ext %>' })))
9394
.pipe(vfs.dest(dest))
94-
.pipe(hash.manifest('assets-manifest.json', { append: true }))
95+
.pipe(gulpif(!preview, hash.manifest('assets-manifest.json', { append: true })))
9596
.pipe(vfs.dest(dest)),
9697
// NOTE use the next line to bundle a JavaScript library that cannot be browserified, like jQuery
9798
//vfs.src(require.resolve('<package-name-or-require-path>'), opts).pipe(concat('js/vendor/<library-name>.js')),
9899
vfs.src('./tailwind.config.js').pipe(concat('js/tailwind.config.js')),
99100
vfs
100101
.src(['css/site.css', 'css/vendor/*.css'], { ...opts, sourcemaps })
101102
.pipe(postcss((file) => ({ plugins: postcssPlugins, options: { file } })))
102-
.pipe(hash({ template: '<%= name %>-<%= hash %><%= ext %>' }))
103+
.pipe(gulpif(!preview, hash({ template: '<%= name %>-<%= hash %><%= ext %>' })))
103104
.pipe(vfs.dest(dest))
104-
.pipe(hash.manifest('assets-manifest.json', { append: true }))
105+
.pipe(gulpif(!preview, hash.manifest('assets-manifest.json', { append: true })))
105106
.pipe(vfs.dest(dest)),
106107
vfs.src('font/*.{ttf,woff*(2)}', opts),
107108
vfs.src('img/**/*.{gif,ico,jpg,png,svg}', opts).pipe(

package-lock.json

Lines changed: 176 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"gulp-connect": "~5.7",
4040
"gulp-eslint": "~6.0",
4141
"gulp-hash": "^4.2.2",
42+
"gulp-if": "^3.0.0",
4243
"gulp-imagemin": "~6.2",
4344
"gulp-postcss": "~9.0",
4445
"gulp-uglify": "~3.0",

src/partials/nav.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
{{~/if}}
77
id="side-nav"
88
class="h-full bg-level1 overflow-y-scroll flex flex-col w-[18.5rem] px-2 pt-2">
9-
{{> page-versions page=../page}}
10-
{{#with @root.page.componentVersion}}
11-
<a class="p-2 mb-1 text-h4 hover:bg-level2 rounded transition-colors !no-underline" href="{{{relativize ./url}}}">{{./title}}</a>
12-
{{/with}}
9+
<div class="flex items-start gap-1 mb-1 ">
10+
{{#with @root.page.componentVersion}}
11+
<a class="flex flex-grow py-1 px-2 text-h4 hover:bg-level2 rounded transition-colors !no-underline" href="{{{relativize ./url}}}">{{./title}}</a>
12+
{{/with}}
13+
{{> page-versions page=../page}}
14+
</div>
1315
{{> nav-tree navigation=this}}
1416
{{> nav-secondary}}
1517
</nav>

src/partials/page-versions.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{{#with page.versions}}
2-
<div class="dropdown my-2">
2+
<div class="dropdown ml-auto">
33
<button id="page-version-dropdown" title="Show other versions of page" class="group dropdown-trigger btn btn-soft btn-primary btn-small" aria-haspopup="true" aria-expanded="false">
4-
Version: <span class="font-bold ml-1">{{@root.page.componentVersion.displayVersion}}{{#if (eq @root.page.component.latest.version @root.page.componentVersion.version)}} (Latest){{/if}}</span>
4+
<span class="font-bold ml-1 text-xs">{{@root.page.componentVersion.displayVersion}}</span>
55
<i class="material-icons text-lg color-primary motion-safe:transition-transform motion-safe:duration-300 motion-safe:ease-in-out ml-[0.15em] group-[.active]:rotate-180">expand_more</i>
66
</button>
7-
<ul class="dropdown-content py-2 bg-body border rounded w-32 z-40" role="menu" aria-orientation="vertical" aria-labelledby="page-version-dropdown">
7+
<ul class="dropdown-content py-2 bg-body border rounded w-48 z-40" role="menu" aria-orientation="vertical" aria-labelledby="page-version-dropdown">
88
{{#each this}}
99
<li>
1010
<a

0 commit comments

Comments
 (0)