-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proj-html): Duplicating global html tags for each page for html …
…project generators (#621) * feat(proj-html): duplicating global html tags for each page for html project generators * Add missing dependency for the html project generator
- Loading branch information
1 parent
df7f4f2
commit e6ed5e7
Showing
5 changed files
with
99 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
FileType, | ||
GeneratedFile, | ||
ProjectPlugin, | ||
ProjectPluginStructure, | ||
} from '@teleporthq/teleport-types' | ||
import { parse, HTMLElement } from 'node-html-parser' | ||
import prettierHTML from '@teleporthq/teleport-postprocessor-prettier-html' | ||
|
||
class ProjectPluginHTMLGeneratprs implements ProjectPlugin { | ||
async runBefore(structure: ProjectPluginStructure) { | ||
return structure | ||
} | ||
|
||
async runAfter(structure: ProjectPluginStructure) { | ||
const { files, uidl } = structure | ||
const entryFile = files.get('entry') | ||
if (!entryFile) { | ||
return structure | ||
} | ||
|
||
const result = parse(entryFile.files[0].content) | ||
const body = result.querySelector('body') | ||
body.childNodes = [] | ||
|
||
if (Object.values(uidl.root?.styleSetDefinitions || {}).length > 0) { | ||
const head = result.querySelector('head') | ||
head.appendChild(new HTMLElement('link', {}, 'rel="stylesheet" href="../style.css"', result)) | ||
} | ||
|
||
files.forEach((fileId, key) => { | ||
const { path } = fileId | ||
if (path.includes('pages')) { | ||
const newFiles: GeneratedFile[] = fileId.files.map((file) => { | ||
if (file.fileType === FileType.HTML) { | ||
body.innerHTML = file.content | ||
const prettyFile = prettierHTML({ | ||
[FileType.HTML]: result.toString(), | ||
}) | ||
|
||
return { name: file.name, content: prettyFile[FileType.HTML], fileType: FileType.HTML } | ||
} | ||
return file | ||
}) | ||
files.set(key, { path, files: newFiles }) | ||
} | ||
}) | ||
|
||
files.delete('entry') | ||
return structure | ||
} | ||
} | ||
|
||
export const pluginHtmlGenerators = Object.freeze(new ProjectPluginHTMLGeneratprs()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters