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

Enhanced function: Add article password #851

Open
23jdn opened this issue Oct 25, 2023 · 0 comments
Open

Enhanced function: Add article password #851

23jdn opened this issue Oct 25, 2023 · 0 comments

Comments

@23jdn
Copy link

23jdn commented Oct 25, 2023

Describe the enhancement

Enhanced function: Add article password

Sometimes we don't want to show part of the web page to everyone, so we can encrypt our web page so that it can be accessed through a password. Similar to the following code, modify "your_site\layouts\posts\single.html", but it does not work for hugo-coder:


{{- $password := $params.password | default "" -}}
     {{- if ne $password "" -}}
         <script>
             (function(){
                 if({{ $password }}){
                     if (prompt('please enter password') != {{ $password }}){
                         alert('password error!');
                         if (history.length === 1) {
                             window.opener = null;
                             window.open('', '_self');
                             window.close();
                         } else {
                             history.back();
                         }
                     }
                 }
             })();
         </script>
     {{- end -}}
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

No branches or pull requests

1 participant