Skip to content

Instantly share code, notes, and snippets.

@jialinhuang00
Created September 15, 2024 16:41
Show Gist options
  • Save jialinhuang00/3a2fcc8087148f72bfb9247bedf16426 to your computer and use it in GitHub Desktop.
Save jialinhuang00/3a2fcc8087148f72bfb9247bedf16426 to your computer and use it in GitHub Desktop.
super handy when you using nextjs and gh-pages seving static pages.
# variables
NEXT = npx next
GIT = git
# defalt
.PHONY: all
all:
@echo "Available targets:"
@echo " make out - Prepare for publishing, a.k.a next build"
@echo " make commit \"Your commit message\" - Commit changes"
@echo " make live - Publish to gh-pages"
@echo " make go \"Your commit message\" - Prepare, commit then publish all in one"
# git commit
.PHONY: commit
commit:
@if [ -z "$(filter-out $@,$(MAKECMDGOALS))" ]; then \
echo "Error: No commit message provided"; \
echo "Usage: make commit \"Your commit message\""; \
exit 1; \
else \
$(GIT) add . && $(GIT) commit -m "$(filter-out $@,$(MAKECMDGOALS))"; \
fi
# next build
.PHONY: out
out:
$(NEXT) build
@echo [your domain] > out/CNAME
@touch out/.nojekyll
# publish online
.PHONY: live
live:
$(GIT) push origin `$(GIT) subtree split --prefix out main`:refs/heads/gh-pages -f
# all in one
.PHONY: go
go:
@if [ -z "$(filter-out $@,$(MAKECMDGOALS))" ]; then \
echo "Error: No commit message provided"; \
echo "Usage: make go \"Your commit message\""; \
exit 1; \
else \
$(MAKE) out && \
$(MAKE) commit "$(filter-out $@,$(MAKECMDGOALS))" && \
$(MAKE) live; \
fi
# get all target
%:
@:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment