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

Title-Heading Comments # are a Thing? ## Maybe? #8

Open
jeremy-farrance opened this issue Jan 3, 2024 · 0 comments
Open

Title-Heading Comments # are a Thing? ## Maybe? #8

jeremy-farrance opened this issue Jan 3, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@jeremy-farrance
Copy link
Owner

Implemented successfully and usefully across PDEG2019, the ability to leave Title Comments that were visible to editors but not he public was considered extremely useful for seasonal and other rotating content. May or may not get used in other contexts but with a minor rewrite, its a solid addition to AccuLadder that might find a fan-base.

Note the variations by number of #s...

@functions {
  // Since TitleComments are now a thing, lets enhance them
  // Leave # as is, ## means highlight (yellow), ### means H1/CAPS
  public string TitleComments_Process(string inTitle, string sep = "#") {
    string title = "title=\"This #Comment is hidden, not visible to the public (users that are not logged in).\"";
    string sep2 = sep + sep;
    string sep3 = sep2 + sep;
    int foundAt = inTitle.IndexOf(sep3);
    if(foundAt > 0) {
      //return inTitle.Insert(foundAt, "?").Trim();
      return inTitle.Replace(sep3, "#").Insert(foundAt, "<span " + title + " class=\"py-1 alert alert-warning\">").Trim() + "</span>";
    }
    foundAt = inTitle.IndexOf(sep2);
    if(foundAt > 0) {
      //return inTitle.Insert(foundAt, "?").Trim();
      return inTitle.Replace(sep2, "#").Insert(foundAt, "<span " + title + "class=\"py-1 alert alert-info\">").Trim() + "</span>";
    }
    return inTitle;
  }
  // only strip if user is not logged in
  public string StripComment_WhenAnon(string inTitle, string sep = "#") {
    if(Request.IsAuthenticated) {
      return TitleComments_Process(inTitle, sep);
    } else {
      return StripComment(inTitle, sep);
    }
  }
  // remove everything after the separator, so "Hi #comment" will become just "Hi"
  public string StripComment(string inTitle, string sep = "#") {
    if(inTitle.Contains(sep)) {
      return inTitle.Substring(0, inTitle.IndexOf(sep)).Trim();
    } else {
      return inTitle.Trim();
    }
  }
}
@jeremy-farrance jeremy-farrance added the enhancement New feature or request label Jan 3, 2024
@jeremy-farrance jeremy-farrance self-assigned this Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant