Skip to content

Commit

Permalink
Añadido: proyecto manu export org files
Browse files Browse the repository at this point in the history
  • Loading branch information
neverkas committed Feb 6, 2023
1 parent a8d4ae3 commit d3ee183
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
38 changes: 38 additions & 0 deletions manu-export-org-files/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
all: down up

b build:
$(info Construyendo imagenes...)
$(call docker_cmd, build)

u up:
$(info Ejecutando contenedor/es...)
$(call docker_cmd, up)

p pause:
$(info Pausando contenedor/es...)
$(call docker_cmd, pause)

s stop:
$(info Deteniendo contenedor/es...)
$(call docker_cmd, stop)

d down:
$(call docker_cmd, down)

l logs:
$(call docker_cmd, logs --tail 50 --follow)

sh:
$(info Accediendo al contentendor en modo interactivo...)
$(call docker_cmd, exec, /bin/sh)

npm:
@docker-compose exec $(CONTAINER_WEBAPP) npm $(ARGS)

export:
$(call make_exec, export.mk, watch)

.PHONY: all sh npm export b build u up s stop l logs d down clean p pause

-include Makefile.conf
-include functions.mk
9 changes: 9 additions & 0 deletions manu-export-org-files/Makefile.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CONTAINER_WEBAPP ?= webapp

# - evitamos definir los nombres de los parámetros que pasamos por terminal
# - alternativa: en la orden de una regla usar $(filter-out $@,$(MAKECMDGOALS))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))

# - requisito para que funcione el paso de parámetros sin warnings
%:
@:
16 changes: 16 additions & 0 deletions manu-export-org-files/export.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM pandoc/core

RUN apk add --no-cache make rsync

RUN addgroup -g 1000 -S pandoc && adduser -u 1000 -G pandoc -D pandoc
USER pandoc

WORKDIR /data
COPY export.mk .
COPY functions.mk .
COPY ./docs ./docs
COPY ./src/views ./src/views

# necesario, porque el punto de entrada por defecto de la imagen base es /bin/pandoc
ENTRYPOINT ["/bin/sh", "-c"]
CMD ["make --no-print-directory -f export.mk watch"]
66 changes: 66 additions & 0 deletions manu-export-org-files/export.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ---------------------------------------------------------------------------
# - MACROS
.DEFAULT_GOAL := export

MAKE += -f export.mk

DOC_PATH := docs
HTML_PATH := src/views
ROOT_PATH := $(shell pwd)
COMPONENTS_PATH := src/components
DOC_SUBDIRS := $(sort $(dir $(wildcard $(DOC_PATH)/*/)))
HTML_SUBDIRS := $(subst $(DOC_PATH),$(HTML_PATH),$(DOC_SUBDIRS))
SUBDIRS := $(DOC_SUBDIRS) $(HTML_SUBDIRS)

DOC_FILES := $(foreach dir, $(DOC_SUBDIRS), $(wildcard $(dir)*.org))
HTML_FILES := $(subst $(DOC_PATH),$(HTML_PATH), $(DOC_FILES))
HTML_FILES := $(patsubst %.org,%.html, $(HTML_FILES))

RM := rm -rfv
MKDIR := mkdir -vp

# ---------------------------------------------------------------------------
# PANDOC CONFIG

PANDOC_PARAMS = \
--from=org --to=html --out=$@ --table-of-contents --toc-depth 3 \
--resource-path=$(ROOT_PATH) \
--template $(COMPONENTS_PATH)/template.html

# si no está definida la variable de entorno, le definimos otro valor
HOST_ENV ?= manjaro

ifeq ($(HOST_ENV), container)
PANDOC_CMD = @pandoc $(PANDOC_PARAMS) $<
else
PANDOC_CMD = \
@docker run --rm \
--volume "$(ROOT_PATH):/data" \
--user $(shell id -u):$(shell id -g) \
pandoc/minimal $(PANDOC_PARAMS) $<
endif

# ---------------------------------------------------------------------------
# - REGLAS

export: $(SUBDIRS) $(HTML_FILES)

watch:
$(info Observando cambios en la documentación para exportar...)
$(call watch)

$(SUBDIRS):
$(info Creando estructura de directorios)
@$(MKDIR) $@

$(HTML_FILES):$(HTML_PATH)/%.html:$(DOC_PATH)/%.org
$(info Exportando a html el fichero $(subst $(DOC_PATH)/,,$<))
$(PANDOC_CMD)

clean:
$(info Borrando archivos html...)
@-$(RM) $(HTML_FILES)

.PHONY: watch export clean

-include functions.mk
11 changes: 11 additions & 0 deletions manu-export-org-files/functions.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define docker_cmd
@docker-compose $1 $(ARGS) $2
endef

define make_exec
@$(MAKE) --no-print-directory -f $1 $2
endef

define watch
@while true; do $(MAKE) -q || $(MAKE) --no-print-directory; sleep 1; done
endef

0 comments on commit d3ee183

Please sign in to comment.