Static sites and dynamic Jamstack apps Atishay Jain Foreword by Steve Francia M A N N I N G Hugo in Action Hugo in Action S J TATIC SITES AND DYNAMIC AMSTACK APPS ATISHAY JAIN FOREWORD BY STEVE FRANCIA MANNING SHELTER ISLAND For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: [email protected] ©2022 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. The author and publisher have made every effort to ensure that the information in this book was correct at press time. The author and publisher do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence, accident, or any other cause, or from any usage of the information herein. Manning Publications Co. Development editor: Katie Sposato Johnson 20 Baldwin Road Technical development editor: Louis Lazaris PO Box 761 Review editor: Ivan Martinović and Adriana Sabo Shelter Island, NY 11964 Production editor: Deirdre Hiam Copy editor: Frances Buran Proofreader: Keri Hales Technical proofreader: Taylor Dolezal Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN 9781617297007 Printed in the United States of America To Ritika, my lifeline. brief contents P 1 S H : L , ....1 ART TATIC UGO WEBSITES OADING FAST BUILDING TO LAST 1 ■ The Jamstack and Hugo 3 2 ■ Live in 30 minutes: You now have a website 25 3 ■ Using markup for content 57 4 ■ Content management with Hugo 89 5 ■ Custom pages and customized content with the Go template language 121 6 ■ Structuring web pages 151 7 ■ Creating your own theme 187 8 ■ Hugo Modules: Plugins for everybody 214 P 2 E J : D , ART XPANDING WITH THE AMSTACK YNAMIC OUTSIDE ..............................................................233 STATIC INSIDE 9 ■ Accessing APIs to enhance functionality 235 10 ■ The power of JavaScript 275 11 ■ Breaking barriers with custom APIs and webhooks 306 12 ■ Adding e-commerce capabilities using the Jamstack 344 13 ■ Wrapping it up 375 vii