Skip to content

Commit

Permalink
feat: Remove unused HTML utils for Vite 1
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Mar 20, 2021
1 parent f9a3bc5 commit 153e41b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
17 changes: 0 additions & 17 deletions src/utils/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,3 @@ export function renderPreloadLinks(files) {

return link
}

export function parseHTML(body = '') {
const [helmet = ''] = body.match(/<html[^>]*?>(.|\s)*?<\/html>/im) || []
let [, headTags = ''] = helmet.match(/<head[^>]*?>((.|\s)*?)<\/head>/im) || []
let [, bodyAttrs = ''] = helmet.match(/<body([^>]*?)>/im) || []
let [, htmlAttrs = ''] = helmet.match(/<html([^>]*?)>/im) || []

if (helmet) {
const viteDataAttribute = /\sdata-v-[\d\w]+/gm
headTags = headTags.replace(viteDataAttribute, '')
bodyAttrs = bodyAttrs.replace(viteDataAttribute, '')
htmlAttrs = htmlAttrs.replace(viteDataAttribute, '')
body = body.replace(helmet, '<!---->')
}

return { body, headTags, bodyAttrs, htmlAttrs }
}
14 changes: 5 additions & 9 deletions src/vue/entry-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createSSRApp } from 'vue'
import { renderToString } from '@vue/server-renderer'
import { createRouter, createMemoryHistory } from 'vue-router'
import { createUrl, getFullPath, withoutSuffix } from '../utils/route'
import { parseHTML, findDependencies, renderPreloadLinks } from '../utils/html'
import { findDependencies, renderPreloadLinks } from '../utils/html'
import { addPagePropsGetterToRoutes } from './utils'
import { renderHeadToString } from '@vueuse/head'
export { ClientOnly } from '../components.mjs'
Expand Down Expand Up @@ -57,15 +57,11 @@ export default function (
router.currentRoute.value.meta.state || {}
)

const rawAppHtml = await renderToString(app, context)
const body = await renderToString(app, context)

// TODO: remove parseHTML when vueuse/head supports ld+json
let {
body = rawAppHtml,
headTags = '',
htmlAttrs = '',
bodyAttrs = '',
} = head ? renderHeadToString(head) : parseHTML(rawAppHtml)
let { headTags = '', htmlAttrs = '', bodyAttrs = '' } = head
? renderHeadToString(head)
: {}

const dependencies = manifest
? findDependencies(context.modules, manifest)
Expand Down

0 comments on commit 153e41b

Please sign in to comment.