Включения
Включения позволяют вставить содержимое одного файла Pug в другой.
//- index.pug
doctype html
html
include includes/head.pug
body
h1 My Site
p Welcome to my super lame site.
include includes/foot.pug
//- includes/head.pug head title My Site script(src='/javascripts/jquery.js') script(src='/javascripts/app.js')
//- includes/foot.pug footer#footer p Copyright (c) foobar
<!DOCTYPE html>
<html>
<head>
<title>My Site</title>
<script src="/javascripts/jquery.js"></script>
<script src="/javascripts/app.js"></script>
</head>
<body>
<h1>My Site</h1>
<p>Welcome to my super lame site.</p>
<footer id="footer">
<p>Copyright (c) foobar</p>
</footer>
</body>
</html> Если путь является абсолютным (например, include /root.pug), он разрешается путём добавления options.basedir. В противном случае пути разрешаются относительно текущего компилируемого файла.
Если расширение файла не указано, .pug автоматически добавляется к имени файла.
Включение простого текста
Включение файлов, не являющихся Pug, просто включает их исходный текст.
//- index.pug
doctype html
html
head
style
include style.css
body
h1 My Site
p Welcome to my super lame site.
script
include script.js
/* style.css */
h1 {
color: red;
}
// script.js
console.log('You are awesome');
<!DOCTYPE html>
<html>
<head>
<style>
/* style.css */
h1 {
color: red;
}
</style>
</head>
<body>
<h1>My Site</h1>
<p>Welcome to my super lame site.</p>
<script>
// script.js
console.log('You are awesome');
</script>
</body>
</html> Включение отфильтрованного текста
Вы можете комбинировать фильтры с включениями, позволяя фильтровать вещи по мере их включения.
//- index.pug
doctype html
html
head
title An Article
body
include:markdown-it article.md
# article.md This is an article written in markdown.
<!DOCTYPE html>
<html>
<head>
<title>An Article</title>
</head>
<body>
<h1>article.md</h1>
<p>This is an article written in markdown.</p>
</body>
</html>
© Pug authors
Licensed under the MIT license.
https://pugjs.org/language/includes.html