Skip to content

Commit

Permalink
additional debug logging in listings
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonstyle committed Sep 30, 2023
1 parent 5d1a873 commit ce7e9d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/project/types/website/listing/website-listing-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,17 @@ export function completeListingItems(
outputFiles: ProjectOutputFile[],
_incremental: boolean,
) {
debug(`[listing] Completing listing items for ${outputFiles.length} files`);
const options = {
remove: { links: true, images: true },
};

debug(`[listing] Creating content reader`);
const contentReader = renderedContentReader(context, options);

// Go through any output files and fix up any feeds associated with them
outputFiles.forEach((outputFile) => {
debug(`[listing] Completing listing items ${outputFile.input}`);
// Does this output file contain a listing?
if (outputFile.format.metadata[kListing]) {
// Read the listing page
Expand All @@ -315,6 +318,7 @@ export function completeListingItems(

listings.forEach((listing) => {
if (typeof (listing) === "object") {
debug(`[listing] Processing listing`);
const listingMetadata = listing as Metadata;
// See if there is a default image
const listingDefaultImage = listingMetadata !== undefined &&
Expand All @@ -327,6 +331,7 @@ export function completeListingItems(
regex.lastIndex = 0;
let match = regex.exec(fileContents);
while (match) {
debug(`[listing] Processing description match`);
// For each placeholder, get its target href, then read the contents of that
// file and inject the contents.
const maxDescLength = parseInt(match[1]);
Expand Down Expand Up @@ -369,6 +374,7 @@ export function completeListingItems(
imgRegex.lastIndex = 0;
let imgMatch = imgRegex.exec(fileContents);
while (imgMatch) {
debug(`[listing] Processing image match`);
const progressive = imgMatch[1] === "true";
const imgHeight = imgMatch[2];
const docRelativePath = imgMatch[3];
Expand All @@ -378,12 +384,17 @@ export function completeListingItems(
progressive,
imgHeight,
);
debug(`[listing] ${docAbsPath}`);
debug(`[listing] ${imgPlaceholder}`);

if (existsSync(docAbsPath)) {
debug(`[listing] exists: ${docAbsPath}`);
const contents = contentReader(docAbsPath, {
remove: { links: true },
});

if (contents.previewImage) {
debug(`[listing] previewImage: ${docAbsPath}`);
const resolveUrl = (path: string) => {
if (isHttpUrl(path)) {
return path;
Expand All @@ -408,11 +419,13 @@ export function completeListingItems(
imgHeight,
);

debug(`[listing] replacing: ${docAbsPath}`);
fileContents = fileContents.replace(
imgPlaceholder,
imgHtml,
);
} else if (listingDefaultImage) {
debug(`[listing] using default image: ${docAbsPath}`);
const imagePreview: PreviewImage = {
src: listingDefaultImage,
};
Expand All @@ -421,12 +434,14 @@ export function completeListingItems(
imageSrc(imagePreview, progressive, imgHeight),
);
} else {
debug(`[listing] using empty div: ${docAbsPath}`);
fileContents = fileContents.replace(
imgPlaceholder,
emptyDiv(imgHeight),
);
}
} else {
debug(`[listing] does not exist: ${docAbsPath}`);
fileContents = fileContents.replace(
imgPlaceholder,
emptyDiv(imgHeight),
Expand Down
5 changes: 5 additions & 0 deletions src/project/types/website/listing/website-listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
} from "./website-listing-index.ts";
import { ProjectOutputFile } from "../../types.ts";
import { formatHasBootstrap } from "../../../../format/html/format-html-info.ts";
import { debug } from "https://deno.land/std@0.185.0/log/mod.ts";

export function listingSupplementalFiles(
project: ProjectContext,
Expand Down Expand Up @@ -295,12 +296,15 @@ export function completeListingGeneration(
incremental: boolean,
) {
// Complete any staged feeds
debug(`[listing] Completing staged feeds in ${context.dir}`);
completeStagedFeeds(context, outputFiles, incremental);

// Ensure any listing items have their rendered descriptions populated
debug(`[listing] Completing listing items in ${context.dir}`);
completeListingItems(context, outputFiles, incremental);

// Write a global listing index
debug(`[listing] Writing global listing index for ${context.dir}`);
updateGlobalListingIndex(context, outputFiles, incremental);
}

Expand Down Expand Up @@ -367,6 +371,7 @@ function listingPostProcess(
options: ListingSharedOptions,
format: Format,
) {
debug(`[listing] Post processing ${listingDescriptors.length} listings`);
// Render categories, if necessary
const categories = options[kFieldCategories];
if (categories) {
Expand Down

0 comments on commit ce7e9d4

Please sign in to comment.