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

Fix theme from upstream #151

Merged
merged 5 commits into from
Jul 11, 2024
Merged

Fix theme from upstream #151

merged 5 commits into from
Jul 11, 2024

Conversation

abtris
Copy link
Owner

@abtris abtris commented Jun 1, 2024

Summary by CodeRabbit

  • New Features

    • Introduced shortcode for expanding content with a toggle feature.
    • Added Microsoft Clarity tracking script if enabled.
  • Bug Fixes

    • Corrected image fetching logic for card displays.
    • Updated conditional check for comments to use the correct Disqus shortname configuration.
    • Adjusted logic for determining if comments are enabled.
  • Improvements

    • Enhanced alignment and styling in the footer.
    • Updated meta tags and added theme name meta tag.
    • Improved job title and organization name rendering.
  • Chores

    • Upgraded Hugo version to 0.128.2.
    • Added local Netlify folder to .gitignore.
  • Refactors

    • Adjusted URL extraction logic for authors and sidebar menus.
    • Unified logic for setting meta tags and Google Analytics tracking.

Copy link
Contributor

coderabbitai bot commented Jun 1, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

This update includes a variety of changes across multiple files within the Academia theme and related scripts for the Hugo static site generator. Key adjustments involve improvements to URL handling, resource retrieval logic, HTML structure, accessibility features, and project setup scripts. Notably, it also includes an upgrade of the Hugo version from 0.122.0 to 0.128.2 and introduces new functionality for handling content expansion and Microsoft Clarity tracking.

Changes

Files/Groups Change Summary
themes/academia/layouts/authors/list.html Updated logic for extracting username from URL.
themes/academia/layouts/partials/docs_sidebar.html Modified URL path extraction for $menu_name.
themes/academia/layouts/partials/li_card.html Changed image resource retrieval parameter to "featured".
themes/academia/layouts/partials/li_list.html Added class col-lg-8 mx-auto to div and removed post summary block.
themes/academia/layouts/partials/navbar.html Changed aria-label attribute from double quotes to backticks.
themes/academia/layouts/partials/page_links_div.html Added Params.doi to conditional HTML rendering check.
themes/academia/layouts/partials/site_footer.html Adjusted row alignment, added margin classes, modified external link target attributes.
themes/academia/layouts/partials/site_head.html Added meta theme-name, Microsoft Clarity script, adjusted og:type and article:published_time.
themes/academia/layouts/partials/widgets/about.html Adjusted commas in job titles and organization name rendering.
themes/academia/layouts/partials/widgets/pages.html Modified closing div tag.
themes/academia/layouts/shortcodes/expand.html Introduced shortcode for expandable content with toggle feature.
themes/academia/scripts/projectSetup.js New script for setting up project folders and structure.
themes/academia/scripts/themeSetup.js New script for setting up theme folders and structure.
netlify.toml Updated Hugo version from 0.122.0 to 0.128.2.
.gitignore Added .netlify folder to ignore list.
themes/academia/layouts/partials/comments.html Updated Disqus shortname reference.
themes/academia/layouts/partials/page_metadata.html Updated Disqus shortname reference.
themes/academia/layouts/partials/site_js.html Updated Disqus shortname reference in comments logic.

Poem

In the land of code, a rabbit plays,
With themes and scripts in dazzling arrays,
URLs refined, comments aligned,
Hugo upgraded, clarity defined.
With joy we hop, through projects anew,
Academia shines, like morning dew.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2ebe0a6 and 829b552.

Files selected for processing (13)
  • themes/academia/layouts/authors/list.html (1 hunks)
  • themes/academia/layouts/partials/docs_sidebar.html (1 hunks)
  • themes/academia/layouts/partials/li_card.html (2 hunks)
  • themes/academia/layouts/partials/li_list.html (1 hunks)
  • themes/academia/layouts/partials/navbar.html (2 hunks)
  • themes/academia/layouts/partials/page_links_div.html (1 hunks)
  • themes/academia/layouts/partials/site_footer.html (2 hunks)
  • themes/academia/layouts/partials/site_head.html (3 hunks)
  • themes/academia/layouts/partials/widgets/about.html (1 hunks)
  • themes/academia/layouts/partials/widgets/pages.html (1 hunks)
  • themes/academia/layouts/shortcodes/expand.html (1 hunks)
  • themes/academia/scripts/projectSetup.js (1 hunks)
  • themes/academia/scripts/themeSetup.js (1 hunks)
Files skipped from review due to trivial changes (4)
  • themes/academia/layouts/partials/li_card.html
  • themes/academia/layouts/partials/widgets/about.html
  • themes/academia/layouts/partials/widgets/pages.html
  • themes/academia/layouts/shortcodes/expand.html
Additional context used
Biome
themes/academia/scripts/projectSetup.js

[error] 1-1: A Node.js builtin module should be imported with the node: protocol.


[error] 2-2: A Node.js builtin module should be imported with the node: protocol.


[error] 12-12: Change to an optional chain.


[error] 33-45: Prefer for...of instead of forEach.


[error] 58-69: Prefer for...of instead of forEach.

themes/academia/scripts/themeSetup.js

[error] 1-1: A Node.js builtin module should be imported with the node: protocol.


[error] 2-2: A Node.js builtin module should be imported with the node: protocol.


[error] 24-24: Change to an optional chain.


[error] 33-45: Prefer for...of instead of forEach.


[error] 61-77: Prefer for...of instead of forEach.

Additional comments not posted (10)
themes/academia/layouts/partials/page_links_div.html (1)

18-18: LGTM! Ensure that the new Params.doi condition is properly documented and tested.

themes/academia/layouts/authors/list.html (1)

17-18: LGTM! Verify that the new URL extraction logic works correctly across different URL formats.

Verification successful

The new URL extraction logic has been successfully verified across different URL formats, and all test cases passed.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the new URL extraction logic in different URL formats.

# Test: Manually test with different URL formats. Expect: Correct extraction of usernames.
echo "Manual testing required."

Length of output: 58



Script:

#!/bin/bash
# Description: Automate the verification of the new URL extraction logic in different URL formats.

# Function to simulate the URL extraction logic
extract_username() {
  local url=$1
  local base_url="https://example.com/"
  local base_excluded=${url#"$base_url"}
  local username=$(echo $base_excluded | cut -d'/' -f2)
  echo $username
}

# Test cases
urls=(
  "https://example.com/user/johndoe"
  "https://example.com/user/janedoe"
  "https://example.com/user/alexsmith"
  "https://example.com/user/maryjane"
)

# Expected usernames
expected_usernames=(
  "johndoe"
  "janedoe"
  "alexsmith"
  "maryjane"
)

# Run tests
for i in "${!urls[@]}"; do
  url=${urls[$i]}
  expected=${expected_usernames[$i]}
  result=$(extract_username "$url")
  if [ "$result" == "$expected" ]; then
    echo "PASS: $url -> $result"
  else
    echo "FAIL: $url -> $result (expected: $expected)"
  fi
done

Length of output: 2230

themes/academia/layouts/partials/site_footer.html (1)

3-4: LGTM! Visually inspect the footer to ensure the alignment and external link handling are as expected.

Also applies to: 17-34

themes/academia/layouts/partials/li_list.html (1)

21-21: LGTM! Check the responsiveness of the new layout on different devices to ensure it scales properly.

themes/academia/layouts/partials/docs_sidebar.html (1)

4-7: LGTM! Verify that the new menu name extraction logic works correctly across different configurations.

themes/academia/scripts/themeSetup.js (3)

4-8: The createNewfolder function correctly creates a new directory. Good use of the recursive option.


10-14: The deleteFolder function safely checks for existence before deletion, which is a good practice.


48-85: The setupTheme function is well-organized and effectively uses helper functions to manage theme setup.

themes/academia/layouts/partials/navbar.html (1)

14-14: The change to backticks for the i18n function call in the aria-label attribute is a good practice for consistency in Hugo templates.

themes/academia/layouts/partials/site_head.html (1)

7-7: The addition of the theme-name meta tag, Microsoft Clarity script, and article:published_time meta tag are well-implemented and enhance the functionality and SEO of the site.

Also applies to: 121-129, 189-189

@@ -0,0 +1,87 @@
const fs = require("fs");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the node: protocol for built-in module imports to ensure compatibility with newer Node.js versions.

- const fs = require("fs");
- const path = require("path");
+ const fs = require("node:fs");
+ const path = require("node:path");

Also applies to: 2-2

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const fs = require("fs");
const fs = require("node:fs");
const path = require("node:path");
Tools
Biome

[error] 1-1: A Node.js builtin module should be imported with the node: protocol.

Comment on lines +30 to +46
const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
const directory = path.join(rootFolder);
const items = fs.readdirSync(directory, { withFileTypes: true });
items.forEach((item) => {
if (item.isDirectory()) {
createNewfolder(destinationRoot, item.name);
iterateFilesAndFolders(path.join(directory, item.name), {
currentFolder: item.name,
destinationRoot: path.join(destinationRoot, item.name),
});
} else {
const sourceFile = path.join(directory, item.name);
const destinationFile = path.join(destinationRoot, item.name);
fs.renameSync(sourceFile, destinationFile);
}
});
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace forEach with for...of for better control over iteration, especially useful if asynchronous operations are needed in the future.

- items.forEach((item) => {
+ for (const item of items) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
const directory = path.join(rootFolder);
const items = fs.readdirSync(directory, { withFileTypes: true });
items.forEach((item) => {
if (item.isDirectory()) {
createNewfolder(destinationRoot, item.name);
iterateFilesAndFolders(path.join(directory, item.name), {
currentFolder: item.name,
destinationRoot: path.join(destinationRoot, item.name),
});
} else {
const sourceFile = path.join(directory, item.name);
const destinationFile = path.join(destinationRoot, item.name);
fs.renameSync(sourceFile, destinationFile);
}
});
};
const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
const directory = path.join(rootFolder);
const items = fs.readdirSync(directory, { withFileTypes: true });
for (const item of items) {
if (item.isDirectory()) {
createNewfolder(destinationRoot, item.name);
iterateFilesAndFolders(path.join(directory, item.name), {
currentFolder: item.name,
destinationRoot: path.join(destinationRoot, item.name),
});
} else {
const sourceFile = path.join(directory, item.name);
const destinationFile = path.join(destinationRoot, item.name);
fs.renameSync(sourceFile, destinationFile);
}
}
};
Tools
Biome

[error] 33-45: Prefer for...of instead of forEach.

Comment on lines +16 to +28
const getFolderName = (rootfolder) => {
const configPath = path.join(
rootfolder,
"exampleSite/config/_default/hugo.toml"
);
const getConfig = fs.readFileSync(configPath, "utf8");
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/);
let selectedTheme = null;
if (match && match[1]) {
selectedTheme = match[1];
}
return selectedTheme;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using optional chaining when accessing potentially undefined properties to enhance code robustness.

-  if (match && match[1]) {
+  if (match?.[1]) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const getFolderName = (rootfolder) => {
const configPath = path.join(
rootfolder,
"exampleSite/config/_default/hugo.toml"
);
const getConfig = fs.readFileSync(configPath, "utf8");
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/);
let selectedTheme = null;
if (match && match[1]) {
selectedTheme = match[1];
}
return selectedTheme;
};
const getFolderName = (rootfolder) => {
const configPath = path.join(
rootfolder,
"exampleSite/config/_default/hugo.toml"
);
const getConfig = fs.readFileSync(configPath, "utf8");
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/);
let selectedTheme = null;
if (match?.[1]) {
selectedTheme = match[1];
}
return selectedTheme;
};
Tools
Biome

[error] 24-24: Change to an optional chain.

Comment on lines +1 to +2
const fs = require("fs");
const path = require("path");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the node: protocol for importing Node.js built-in modules.

- const fs = require("fs");
- const path = require("path");
+ const fs = require("node:fs");
+ const path = require("node:path");
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
Tools
Biome

[error] 1-1: A Node.js builtin module should be imported with the node: protocol.


[error] 2-2: A Node.js builtin module should be imported with the node: protocol.

const getConfig = fs.readFileSync(configPath, "utf8");
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/);
let selectedTheme = null;
if (match && match[1]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use optional chaining to simplify the code.

-  if (match && match[1]) {
+  if (match?.[1]) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (match && match[1]) {
if (match?.[1]) {
Tools
Biome

[error] 12-12: Change to an optional chain.

Comment on lines +33 to +45
items.forEach((item) => {
if (item.isDirectory()) {
createNewfolder(destinationRoot, item.name);
iterateFilesAndFolders(path.join(directory, item.name), {
currentFolder: item.name,
destinationRoot: path.join(destinationRoot, item.name),
});
} else {
const sourceFile = path.join(directory, item.name);
const destinationFile = path.join(destinationRoot, item.name);
fs.renameSync(sourceFile, destinationFile);
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer for...of instead of forEach for better readability and performance.

- items.forEach((item) => {
+ for (const item of items) {

Also applies to: 58-69

Committable suggestion was skipped due low confidence.

Tools
Biome

[error] 33-45: Prefer for...of instead of forEach.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 829b552 and bdcfd05.

Files selected for processing (1)
  • netlify.toml (1 hunks)
Files skipped from review due to trivial changes (1)
  • netlify.toml

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bdcfd05 and 8842b96.

Files selected for processing (4)
  • themes/academia/layouts/partials/comments.html (1 hunks)
  • themes/academia/layouts/partials/page_metadata.html (1 hunks)
  • themes/academia/layouts/partials/site_head.html (3 hunks)
  • themes/academia/layouts/partials/site_js.html (1 hunks)
Files skipped from review due to trivial changes (1)
  • themes/academia/layouts/partials/comments.html
Additional comments not posted (5)
themes/academia/layouts/partials/page_metadata.html (1)

52-52: Update reference to Disqus shortname.

The reference to the Disqus shortname has been updated from site.DisqusShortname to site.Config.Services.Disqus.Shortname. Ensure that this change is consistent throughout the codebase.

Verification successful

Update reference to Disqus shortname verified.

The reference to the Disqus shortname has been updated consistently from site.DisqusShortname to site.Config.Services.Disqus.Shortname across the codebase. The old reference is no longer present.

  • themes/academia/layouts/partials/site_js.html
  • themes/academia/layouts/partials/page_metadata.html
  • themes/academia/layouts/partials/comments.html
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the reference to Disqus shortname is updated consistently.

# Test: Search for the old reference. Expect: No occurrences.
rg --type yaml --type html --type js $'site.DisqusShortname'

# Test: Search for the new reference. Expect: Only valid occurrences.
rg --type yaml --type html --type js $'site.Config.Services.Disqus.Shortname'

Length of output: 845

themes/academia/layouts/partials/site_js.html (1)

48-50: Update reference to Disqus shortname.

The reference to the Disqus shortname has been updated from site.DisqusShortname to site.Config.Services.Disqus.Shortname. Ensure that this change is consistent throughout the codebase.

themes/academia/layouts/partials/site_head.html (3)

7-7: Add meta tag for theme name.

A new meta tag for the theme name has been added. This is a useful addition for identifying the theme in use.


120-129: Include Microsoft Clarity script conditionally.

The Microsoft Clarity script is conditionally included if site.Params.microsoft_clarity is set. This is a good practice to ensure the script is only loaded when necessary.


Line range hint 130-137:
Include Google Analytics script conditionally.

The Google Analytics script is conditionally included if site.Config.Services.GoogleAnalytics.ID is set. This is a good practice to ensure the script is only loaded when necessary.

@abtris abtris merged commit 7f8cabc into master Jul 11, 2024
5 of 9 checks passed
@abtris abtris deleted the abtris/fix-theme branch July 11, 2024 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant