Use the site name in opengraph tags

…which involves passing around the index file to a lot more places
This commit is contained in:
Rhiannon Morris 2022-08-11 01:54:12 +02:00
parent 73cd0ca74e
commit f51ea184bb
5 changed files with 45 additions and 31 deletions

View File

@ -147,17 +147,19 @@ endef
# args:
# 1. gallery prefix
# 2. build dir
# 3. data dir
# 4. other flags
# 2. index filename
# 3. build dir
# 4. data dir
# 5. other flags
define depend-single
echo "[deps] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) depend-single $(4) \
$(MAKEPAGES) $(MPFLAGS) depend-single $(5) \
--output "$@" \
--prefix "$(1)" \
--build-dir "$(2)" \
--data-dir "$(3)" $<
--index "$(2)" \
--build-dir "$(3)" \
--data-dir "$(4)" $<
endef
# args
@ -178,14 +180,16 @@ endef
# args:
# 1. data dir
# 2. gallery prefix
# 3. other flags
# 3. index file
# 4. other flags
define single
echo "[single] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) single $(3) \
$(MAKEPAGES) $(MPFLAGS) single $(4) \
--root $(ROOT) \
--data-dir "$(1)" \
--prefix "$(2)" \
--index "$(3)" \
--output "$@" \
$<
endef

View File

@ -13,17 +13,19 @@ import System.FilePath
dependSingle :: FilePath -- ^ yaml file name (relative to data dir!)
-> FilePath -- ^ index file name
-> Info
-> FilePath -- ^ output prefix
-> FilePath -- ^ build dir
-> Bool -- ^ include nsfw?
-> Text
dependSingle yamlDir info prefix build nsfw =
toLazyText $ dependSingle' yamlDir info prefix build nsfw
dependSingle yamlDir indexFile info prefix build nsfw =
toLazyText $ dependSingle' yamlDir indexFile info prefix build nsfw
dependSingle' :: FilePath -> Info -> FilePath -> FilePath -> Bool -> Builder
dependSingle' yamlDir info prefix build nsfw =
[b|$page: $deps $$(MAKEPAGES)|]
dependSingle' :: FilePath -> FilePath -> Info -> FilePath -> FilePath -> Bool
-> Builder
dependSingle' yamlDir indexFile info prefix build nsfw =
[b|$page: $deps $indexFile $$(MAKEPAGES)|]
where
images = #all if nsfw then #images info else #sfwImages info
@ -79,24 +81,25 @@ dependGallery' (GalleryInfo {prefix, filters})
gallery = build </> prefix </> "index.html"
rss = build </> prefix </> "rss.xml"
rules = makeRules prefix filters build data_ tmp
rules = makeRules prefix indexFile filters build data_ tmp
inc d = tmp </> prefix </> takeDirectory d <.> "mk"
incFiles = unwords $ map inc files
incs = if null infos then "" else [b|include $incFiles|]
makeRules :: FilePath -- ^ prefix
-> FilePath -- ^ index file
-> GalleryFilters
-> FilePath -- ^ build dir
-> FilePath -- ^ data dir
-> FilePath -- ^ tmp dir
-> Builder
makeRules prefix filters build data_ tmp = [b|@0
makeRules prefix indexFile filters build data_ tmp = [b|@0
$buildPrefix/%/index.html: $data_/%/info.yaml $$(MAKEPAGES)
$$(call single,$data_,$prefix,$flags)
$$(call single,$data_,$prefix,$indexFile,$flags)
$tmpPrefix/%.mk: $data_/%/info.yaml $$(MAKEPAGES)
$$(call depend-single,$prefix,$build,$data_,$flags)
$$(call depend-single,$prefix,$indexFile,$build,$data_,$flags)
$buildPrefix/%: $tmp/%
$$(call copy,-l)

View File

@ -47,11 +47,12 @@ main = do
main2 mode
main2 :: HasVerbose => ModeOptions -> IO ()
main2 (SinglePage {root, file, prefix, dataDir, nsfw, output}) = do
main2 (SinglePage {root, file, prefix, index, dataDir, nsfw, output}) = do
siteName <- #title <$> readYAML @IndexInfo index
info <- readYAML file
printV $ "contents" := info
let dir = takeDirectory $ makeRelative dataDir file
page <- SinglePage.make root prefix nsfw dataDir dir info
page <- SinglePage.make root siteName prefix nsfw dataDir dir info
writeOutput output page
main2 (GalleryPage {root, files, prefix, index, output, dataDir}) = do
@ -77,12 +78,12 @@ main2 (RSS {files, root, index, prefix, output, dataDir}) = do
let rss = RSS.make root ginfo output' infos
writeOutput output rss
main2 (DependSingle {file, nsfw, output, prefix, buildDir, dataDir}) = do
main2 (DependSingle {index, file, nsfw, output, prefix, buildDir, dataDir}) = do
info <- readYAML file
printV $ "contents" := info
let dir = takeDirectory $ makeRelative dataDir file
printV $ "dir" := dir
let deps = dependSingle dir info prefix buildDir nsfw
let deps = dependSingle dir index info prefix buildDir nsfw
writeOutput output deps
main2 (DependGallery {file, output, buildDir, dataDir, tmpDir, infoName}) = do

View File

@ -15,6 +15,7 @@ data ModeOptions =
root :: Text,
file :: FilePath,
prefix :: FilePath,
index :: FilePath,
dataDir :: FilePath,
nsfw :: Bool,
output :: Maybe FilePath
@ -45,6 +46,7 @@ data ModeOptions =
nsfw :: Bool,
output :: Maybe FilePath,
prefix :: FilePath,
index :: FilePath,
buildDir :: FilePath,
dataDir :: FilePath
}
@ -80,7 +82,8 @@ optionsParser = globalOpts `info` mainInfo where
single = command "single" $ singleOpts `info` singleInfo
singleOpts =
SinglePage <$> root <*> file <*> prefix <*> dataDir <*> nsfwS <*> output
SinglePage <$> root <*> file <*> prefix <*> indexFile
<*> dataDir <*> nsfwS <*> output
root = strOption $
short 'R' <> long "root" <> metavar "URL" <>
help "website root (no trailing slash)"
@ -90,6 +93,9 @@ optionsParser = globalOpts `info` mainInfo where
short 'p' <> long "prefix" <> metavar "DIR" <>
value "" <>
help "gallery directory prefix"
indexFile = strOption $
short 'i' <> long "index" <> metavar "FILE" <>
help "path to index file"
nsfwS = switch $
short 'n' <> long "nsfw" <>
help "include nsfw versions"
@ -107,9 +113,6 @@ optionsParser = globalOpts `info` mainInfo where
galleryOpts =
GalleryPage <$> root <*> files <*> prefix
<*> indexFile <*> output <*> dataDir
indexFile = strOption $
short 'i' <> long "index" <> metavar "FILE" <>
help "path to index file"
files = many $ strArgument $
metavar "FILE..." <> help "yaml files to read"
galleryInfo = progDesc "generate a gallery page"
@ -122,7 +125,7 @@ optionsParser = globalOpts `info` mainInfo where
dependSingle = command "depend-single" $ dsOpts `info` dsInfo
dsOpts =
DependSingle <$> file <*> nsfwS <*> output <*> prefix
<*> buildDir <*> dataDir
<*> indexFile <*> buildDir <*> dataDir
buildDir = strOption $
short 'B' <> long "build-dir" <> metavar "DIR" <> value "_build" <>
help "build directory (default: _build)"

View File

@ -28,16 +28,19 @@ instance Show NoEligibleImages where
make :: Text -- ^ website root
-> Text -- ^ website name
-> FilePath -- ^ gallery prefix
-> Bool -- ^ nsfw?
-> FilePath -- ^ data dir
-> FilePath -- ^ subdir of datadir containing this @info.yaml@
-> Info -> IO Lazy.Text
make root prefix nsfw dataDir dir info =
toLazyText <$> make' root prefix nsfw dataDir dir info
make root siteName prefix nsfw dataDir dir info =
toLazyText <$> make' root siteName prefix nsfw dataDir dir info
make' :: Text -> FilePath -> Bool -> FilePath -> FilePath -> Info -> IO Builder
make' root prefix nsfw _dataDir dir info@(Info {date, title, artist, bg}) = do
make' :: Text -> Text -> FilePath -> Bool -> FilePath -> FilePath -> Info
-> IO Builder
make' root siteName prefix nsfw _dataDir dir
info@(Info {date, title, artist, bg}) = do
let images = imagesFor nsfw info
let undir = joinPath (replicate (length (splitPath dir)) "..")
@ -104,7 +107,7 @@ make' root prefix nsfw _dataDir dir info@(Info {date, title, artist, bg}) = do
<meta property=og:type content=og:website>
<meta property=og:title content="$title">
<meta property=og:site_name content="$title">
<meta property=og:site_name content="$siteName">
<meta property=og:description content="$desc">
<meta property=og:image content="$url/$thumb">
<meta property=og:url content="$url">