Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named links upstream #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ ifeq ($(MAKE_SHORT_POSTS),yes)
else
cp $(BUILD_DIR)/404.html $@
endif
if [ -n "$$(op_is_set "$(METADATA_DIR)/$*/options" named)" ]; then \
cp $@ "$(BUILD_DIR)/$$(op_get "$(METADATA_DIR)/$*/options" named).html"; \
fi

# Short source files, like build/p/abcd1234.bm
# This also takes care of regular source files, like
Expand Down Expand Up @@ -326,6 +329,9 @@ else
mv $@ $(filter %-$*.asc,$(BUILT_SIG_PAGES))
cp $(BUILD_DIR)/404.html $@
endif
if [ -n "$$(op_is_set "$(METADATA_DIR)/$(subst .html,,$*)/options" named)" ]; then \
cp $@ "$(BUILD_DIR)/$$(op_get "$(METADATA_DIR)/$(subst .html,,$*)/options" named).asc"; \
fi

# Homepage, some number of post previews. Follows the same general formula of
# post generation: generate everything in order, pipe through m4, then dump into
Expand Down
17 changes: 14 additions & 3 deletions internal/globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function build_content_header {
[[ "${PREFER_SHORT_POSTS}" == "yes" ]] &&
POST_LINK="${ROOT_URL}/p/${POST}.html" ||
POST_LINK="${ROOT_URL}/posts/${POST_FILE}"
[ -n "$(op_is_set "${METADATA_DIR}/${POST}/options" named)" ] &&
POST_LINK="${ROOT_URL}/$(op_get "${METADATA_DIR}/${POST}/options" named).html"
(( "${#OPTS[@]}" > 0 )) && [[ " ${OPTS[@]} " =~ " for-preview " ]] &&
TITLE="<a href='${POST_LINK}'>${TITLE}</a>"
DATE="$(get_date "${HEADERS}")"
Expand All @@ -95,6 +97,8 @@ function build_content_header {
[[ "${MAKE_SHORT_POSTS}" == "yes" ]] &&
PERMALINK="${ROOT_URL}/p/$(get_id "${HEADERS}").html" ||
PERMALINK=
[ -n "$(op_is_set "${METADATA_DIR}/${POST}/options" named)" ] &&
PERMALINK="$POST_LINK"
IS_PINNED="$(op_get "${OPTIONS}" pinned)"
(( "${#OPTS[@]}" > 0 )) && [[ " ${OPTS[@]} " =~ " for-preview " ]] &&
[[ "${IS_PINNED}" != "" ]] &&
Expand Down Expand Up @@ -162,8 +166,10 @@ function build_postindex {
ID="$(basename $(dirname "${P}"))"
TITLE="$(get_title "${P}")"
[[ "${PREFER_SHORT_POSTS}" == "yes" ]] &&
LINK="/p/${ID}.html" ||
LINK="/posts/$(echo "${TITLE}" | title_to_post_url)${TITLE_SEPARATOR_CHAR}${ID}.html"
LINK="${ROOT_URL}/p/${ID}.html" ||
LINK="${ROOT_URL}/posts/$(echo "${TITLE}" | title_to_post_url)${TITLE_SEPARATOR_CHAR}${ID}.html"
[ -n "$(op_is_set "${METADATA_DIR}/${ID}/options" named)" ] &&
LINK="${ROOT_URL}/$(op_get "${METADATA_DIR}/${ID}/options" named).html"
AUTHOR="$(get_author "${P}")"
DATE="$(get_date "${P}")"
DATE_PRETTY="$(ts_to_date "${DATE_FRMT}" "${DATE}")"
Expand Down Expand Up @@ -237,6 +243,8 @@ function build_tagindex {
else
LINK="/posts/$(echo "${TITLE}" | title_to_post_url)${TITLE_SEPARATOR_CHAR}${ID}.html"
fi
[ -n "$(op_is_set "${METADATA_DIR}/${ID}/options" named)" ] &&
LINK="${ROOT_URL}/$(op_get "${METADATA_DIR}/${ID}/options" named).html"
AUTHOR="$(get_author "${HEADERS}")"
echo "<li><a href='${LINK}'>${TITLE}</a> by ${AUTHOR} on ${DATE_PRETTY}</li>" | tee -a "${TMP_TAG_FILE}"
fi
Expand Down Expand Up @@ -534,7 +542,10 @@ function post_markdown {
[[ "${PREFER_SHORT_POSTS}" == "yes" ]] && \
LINK="/p/${ID}.html" || \
LINK="/posts/$(get_title "${METADATA_DIR}/${ID}/headers" | title_to_post_url)${TITLE_SEPARATOR_CHAR}${ID}.html"
sed "s|\(<a href=['\"]\)\(#.*\)|\1${LINK}\2|" "${TMP1}" > "${TMP2}"

[ -n "$(op_is_set "${METADATA_DIR}/${ID}/options" named)" ] &&
LINK="/$(op_get "${METADATA_DIR}/${ID}/options" named).html"
sed "s|\(<a href=['\"]\)\(#.*\)|\1${ROOT_URL}${LINK}\2|" "${TMP1}" > "${TMP2}"
else
cat "${TMP1}" > "${TMP2}"
fi
Expand Down