Skip to content

Commit

Permalink
mini naming refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Feb 17, 2021
1 parent da0d8ed commit 1be7c07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions packages/cli/src/plugins/resource/plugin-optimization-mpa.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class OptimizationMPAResource extends ResourceInterface {
this.libPath = '@greenwood/router/router.js';
}

// TODO make this work using this.libPath
async shouldResolve(url) {
return Promise.resolve(url.indexOf(this.libPath) >= 0);
}
Expand Down Expand Up @@ -46,19 +47,19 @@ class OptimizationMPAResource extends ResourceInterface {
.replace('.greenwood/', '')
.replace('//', '/');

const routes = this.compilation.graph.map((page) => {
const routeTags = this.compilation.graph.map((page) => {
const template = path.extname(page.filename) === '.html'
? page.route
: page.template;
const id = page.route === '/'
const key = page.route === '/'
? ''
: page.route.slice(0, page.route.lastIndexOf('/'));

if (url.replace(scratchDir, '') === `${page.route}index.html`) {
currentTemplate = template;
}
return `
<greenwood-route data-route="${page.route}" data-template="${template}" data-id="/_routes${id}/index.html"></greenwood-route>
<greenwood-route data-route="${page.route}" data-template="${template}" data-key="/_routes${key}/index.html"></greenwood-route>
`;
});

Expand All @@ -70,7 +71,7 @@ class OptimizationMPAResource extends ResourceInterface {

await fs.promises.writeFile(outputBundlePath, bodyContents);

// TODO this should come from @greenwood/router in cli/lib/ folder
// TODO this src should come from @greenwood/router in cli/lib/ folder
body = body.replace('</head>', `
<script type="module" src="/scripts/router.js"></script>\n
<script>
Expand All @@ -86,7 +87,7 @@ class OptimizationMPAResource extends ResourceInterface {
${bodyContents}\n
</router-outlet>
${routes.join('\n')}
${routeTags.join('\n')}
</body>
`);

Expand Down
4 changes: 2 additions & 2 deletions www/scripts/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ document.addEventListener('click', function(e) {
class RouteComponent extends HTMLElement {
loadRoute() {
console.debug('load route ->', this.getAttribute('data-route'));
console.debug('with bundle ->', this.getAttribute('data-id'));
fetch(this.getAttribute('data-id'))
console.debug('with bundle ->', this.getAttribute('data-key'));
fetch(this.getAttribute('data-key'))
.then(res => res.text())
.then((response) => {
document.getElementsByTagName('router-outlet')[0].innerHTML = response;
Expand Down

0 comments on commit 1be7c07

Please sign in to comment.